blob: 2b7eff86001580814cc53b549048defaa44407c1 [file] [log] [blame]
Radek Krejci9b4ca392015-04-10 08:31:27 +02001/**
Radek Krejci3045cf32015-05-28 10:58:52 +02002 * @file libyang.h
Radek Krejci9b4ca392015-04-10 08:31:27 +02003 * @author Radek Krejci <rkrejci@cesnet.cz>
Radek Krejci3045cf32015-05-28 10:58:52 +02004 * @brief The main libyang public header.
Radek Krejci9b4ca392015-04-10 08:31:27 +02005 *
Radek Krejci792f52f2017-02-28 16:36:31 +01006 * Copyright (c) 2015-2017 CESNET, z.s.p.o.
Radek Krejci9b4ca392015-04-10 08:31:27 +02007 *
Radek Krejci54f6fb32016-02-24 12:56:39 +01008 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
Michal Vasko8de098c2016-02-26 10:00:25 +010011 *
Radek Krejci54f6fb32016-02-24 12:56:39 +010012 * https://opensource.org/licenses/BSD-3-Clause
Radek Krejci9b4ca392015-04-10 08:31:27 +020013 */
14
15#ifndef LY_LIBYANG_H_
16#define LY_LIBYANG_H_
17
Radek Krejcida04f4a2015-05-21 12:54:09 +020018#include <stdio.h>
19
Michal Vasko2d162e12015-09-24 14:33:29 +020020#include "tree_schema.h"
21#include "tree_data.h"
Radek Krejcic6704c82015-10-06 11:12:45 +020022#include "xml.h"
Radek Krejci41912fe2015-10-22 10:22:12 +020023#include "dict.h"
Radek Krejcida04f4a2015-05-21 12:54:09 +020024
Radek Krejci39d8d0d2015-08-17 13:42:45 +020025#ifdef __cplusplus
26extern "C" {
27#endif
28
Radek Krejci60cdf282016-10-10 16:22:22 +020029#define LY_VERSION_MAJOR @LIBYANG_MAJOR_VERSION@ /**< libyang major version number */
30#define LY_VERSION_MINOR @LIBYANG_MINOR_VERSION@ /**< libyang minor version number */
31#define LY_VERSION_MICRO @LIBYANG_MICRO_VERSION@ /**< libyang micro version number */
32
Radek Krejci26715a42015-07-29 14:10:45 +020033/**
Radek Krejcidef50022016-02-01 16:38:32 +010034 * @mainpage About
35 *
36 * libyang is a library implementing processing of the YANG schemas and data modeled by the YANG language. The
37 * library is implemented in C for GNU/Linux and provides C API.
38 *
39 * @section about-features Main Features
40 *
Radek Krejci89db0592017-02-16 15:07:13 +010041 * - [Parsing (and validating) schemas](@ref howtoschemasparsers) in YANG format.
42 * - [Parsing (and validating) schemas](@ref howtoschemasparsers) in YIN format.
43 * - [Parsing, validating and printing instance data](@ref howtodata) in XML format.
44 * - [Parsing, validating and printing instance data](@ref howtodata) in JSON format
45 * ([RFC 7951](https://tools.ietf.org/html/rfc7951)).
46 * - [Manipulation with the instance data](@ref howtodatamanipulators).
Radek Krejci89db0592017-02-16 15:07:13 +010047 * - Support for [default values in the instance data](@ref howtodatawd) ([RFC 6243](https://tools.ietf.org/html/rfc6243)).
Radek Krejci792f52f2017-02-28 16:36:31 +010048 * - Support for [YANG extensions](@ref howtoschemaextensions).
49 * - Support for [YANG Metadata](@ref howtoschemametadata) ([RFC 7952](https://tools.ietf.org/html/rfc6243)).
Radek Krejcidef50022016-02-01 16:38:32 +010050 *
Radek Krejcidaa080f2016-10-05 08:38:09 +020051 * The current implementation covers YANG 1.0 ([RFC 6020](https://tools.ietf.org/html/rfc6020)) as well as
52 * YANG 1.1 ([RFC 7950](https://tools.ietf.org/html/rfc7950)).
Radek Krejci8b13fc02016-04-18 13:08:04 +020053 *
Radek Krejcidef50022016-02-01 16:38:32 +010054 * @subsection about-features-others Extra (side-effect) Features
55 *
56 * - XML parser.
57 * - Optimized string storage (dictionary).
58 *
59 * @section about-license License
60 *
Radek Krejci792f52f2017-02-28 16:36:31 +010061 * Copyright (c) 2015-2017 CESNET, z.s.p.o.
Radek Krejcidef50022016-02-01 16:38:32 +010062 *
63 * (The BSD 3-Clause License)
64 *
65 * Redistribution and use in source and binary forms, with or without
66 * modification, are permitted provided that the following conditions
67 * are met:
68 * 1. Redistributions of source code must retain the above copyright
69 * notice, this list of conditions and the following disclaimer.
70 * 2. Redistributions in binary form must reproduce the above copyright
71 * notice, this list of conditions and the following disclaimer in
72 * the documentation and/or other materials provided with the
73 * distribution.
74 * 3. Neither the name of the Company nor the names of its contributors
75 * may be used to endorse or promote products derived from this
76 * software without specific prior written permission.
77 */
78
79/**
Radek Krejci26715a42015-07-29 14:10:45 +020080 * @page howto How To ...
81 *
82 * - @subpage howtocontext
Radek Krejcid9ba3e32015-07-30 15:08:18 +020083 * - @subpage howtoschemas
84 * - @subpage howtodata
Michal Vasko0f14ba62016-03-21 15:38:11 +010085 * - @subpage howtoxpath
Radek Krejcidef50022016-02-01 16:38:32 +010086 * - @subpage howtoxml
87 * - @subpage howtothreads
Radek Krejci26715a42015-07-29 14:10:45 +020088 * - @subpage howtologger
89 */
Radek Krejcida04f4a2015-05-21 12:54:09 +020090
Radek Krejci26715a42015-07-29 14:10:45 +020091/** @page howtocontext Context
92 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +020093 * The context concept allows callers to work in environments with different sets of YANG schemas.
Radek Krejci26715a42015-07-29 14:10:45 +020094 *
95 * The first step in libyang is to create a new context using ly_ctx_new(). It returns a handler
96 * used in the following work.
97 *
98 * When creating a new context, search dir can be specified (NULL is accepted) to provide directory
99 * where libyang will automatically search for schemas being imported or included. The search path
Radek Krejciabacdb52017-06-12 16:40:58 +0200100 * can be later changed via ly_ctx_set_searchdir() and ly_ctx_unset_searchdrs() functions. If the search dir
Michal Vasko2d051a12017-04-21 09:28:57 +0200101 * is specified, it is explored first. Except the searchpath, also all its subdirectories (and symlinks) are
Radek Krejcida9f8392017-03-25 19:40:56 -0500102 * taken into account. In case the module is not found, libyang tries to find the (sub)module also in current
103 * working working directory. Note, that in this case only the current directory without any other subdirectory
Radek Krejciabacdb52017-06-12 16:40:58 +0200104 * is examined. This automatic searching can be completely avoided when the caller sets module searching callback
Michal Vaskof53187d2017-01-13 13:23:14 +0100105 * (#ly_module_imp_clb) via ly_ctx_set_module_imp_clb().
Radek Krejci26715a42015-07-29 14:10:45 +0200106 *
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200107 * Schemas are added into the context using [parser functions](@ref howtoschemasparsers) - \b lys_parse_*().
Michal Vaskof53187d2017-01-13 13:23:14 +0100108 * In case of schemas, also ly_ctx_load_module() can be used - in that case the #ly_module_imp_clb or automatic
Radek Krejci1fbe8582016-09-15 09:40:11 +0200109 * search in search dir and in the current working directory is used.
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200110 *
111 * Similarly, data trees can be parsed by \b lyd_parse_*() functions. Note, that functions for schemas have \b lys_
Michal Vasko346b5f32017-03-07 10:42:40 +0100112 * prefix while functions for instance data have \b lyd_ prefix. It can happen during data parsing that a schema is
113 * required and __not found__ in the context or the schema is found, but is __only imported__, not implemented (so the
114 * data cannot actually be instantiated). In these cases, a callback is called, which should add this schema into
115 * the context or change its conformance to implemented. You can set the callback using ly_ctx_set_module_data_clb()
116 * (more in @ref howtodataparsers and @ref howtodatavalidation).
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200117 *
Radek Krejciee674072016-09-15 10:37:40 +0200118 * Context can hold multiple revisions of the same schema, but only one of them can be implemented. The schema is not
119 * implemented in case it is automatically loaded as import for another module and it is not referenced in such
120 * a module (and no other) as target of leafref, augment or deviation. All modules with deviation definition are always
121 * marked as implemented. The imported (not implemented) module can be set implemented by lys_set_implemented(). But
122 * the implemented module cannot be changed back to just imported module. The imported modules are used only as a
123 * source of definitions for types (including identities) and uses statements. The data in such a modules are
124 * ignored - caller is not allowed to create the data defined in the model via data parsers, the default nodes are
Radek Krejci819dd4b2017-03-07 15:35:48 +0100125 * not added into any data tree and mandatory nodes are not checked in the data trees. This can be changed by
126 * ly_ctx_set_allimplemented() function which causes that all the imported modules are automatically set to be
127 * implemented.
Radek Krejci26715a42015-07-29 14:10:45 +0200128 *
Radek Krejci31fb8be2016-06-23 15:26:26 +0200129 * Context holds all modules and their submodules internally. To get
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200130 * a specific module or submodule, use ly_ctx_get_module() and ly_ctx_get_submodule(). There are some additional
Radek Krejci31fb8be2016-06-23 15:26:26 +0200131 * alternatives to these functions (with different parameters). If you need to do something with all the modules or
Michal Vasko462be9a2016-04-05 11:24:08 +0200132 * submodules in the context, it is advised to iterate over them using ly_ctx_get_module_iter(), it is
133 * the most efficient way. Alternatively, the ly_ctx_info() function can be used to get complex information
134 * about the schemas in the context in the form of data tree defined by
Radek Krejcibd9e8d22016-02-03 14:11:48 +0100135 * <a href="https://tools.ietf.org/html/draft-ietf-netconf-yang-library-04">ietf-yang-library</a> schema.
Michal Vaskoac7f4222016-09-21 09:02:29 +0200136 * To get a specific node defined in a module in the context, ly_ctx_get_node() can be used.
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200137 *
Radek Krejci0ec51da2016-12-14 16:42:03 +0100138 * Modules held by a context can be removed by ly_ctx_remove_module(). Besides removing the module, it is possible
139 * just to disable it with lys_set_disabled(). In this case the module is hidden in the context (disabled modules can
140 * be iterated via ly_ctx_get_disabled_module_iter()) and not used during the common work with the context. The module
141 * is enabled explicitly by calling lys_set_enabled() or implicitly by the request to load the schema (directly or
142 * indirectly via import of another module) into the context.
143 *
144 * To clean the context from all the loaded modules (except the [internal modules](@ref howtoschemasparsers)), the
145 * ly_ctx_clean() function can be used. To remove the context, there is ly_ctx_destroy() function.
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200146 *
Radek Krejcidef50022016-02-01 16:38:32 +0100147 * - @subpage howtocontextdict
148 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200149 * \note API for this group of functions is available in the [context module](@ref context).
150 *
Radek Krejcidef50022016-02-01 16:38:32 +0100151 * Functions List
152 * --------------
153 * - ly_ctx_new()
154 * - ly_ctx_set_searchdir()
Radek Krejcida9f8392017-03-25 19:40:56 -0500155 * - ly_ctx_unset_searchdirs()
Radek Krejcidef50022016-02-01 16:38:32 +0100156 * - ly_ctx_get_searchdir()
Michal Vaskof53187d2017-01-13 13:23:14 +0100157 * - ly_ctx_set_module_imp_clb()
158 * - ly_ctx_get_module_imp_clb()
159 * - ly_ctx_set_module_data_clb()
160 * - ly_ctx_get_module_data_clb()
Radek Krejci819dd4b2017-03-07 15:35:48 +0100161 * - ly_ctx_set_allimplemented()
162 * - ly_ctx_unset_allimplemented()
Radek Krejcidef50022016-02-01 16:38:32 +0100163 * - ly_ctx_load_module()
164 * - ly_ctx_info()
Michal Vaskod7957c02016-04-01 10:27:26 +0200165 * - ly_ctx_get_module_iter()
Radek Krejci0ec51da2016-12-14 16:42:03 +0100166 * - ly_ctx_get_disabled_module_iter()
Radek Krejcidef50022016-02-01 16:38:32 +0100167 * - ly_ctx_get_module()
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200168 * - ly_ctx_get_module_older()
Radek Krejcidef50022016-02-01 16:38:32 +0100169 * - ly_ctx_get_module_by_ns()
Radek Krejcidef50022016-02-01 16:38:32 +0100170 * - ly_ctx_get_submodule()
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200171 * - ly_ctx_get_submodule2()
Michal Vasko3edeaf72016-02-11 13:17:43 +0100172 * - ly_ctx_get_node()
Radek Krejci0ec51da2016-12-14 16:42:03 +0100173 * - ly_ctx_remove_module()
174 * - ly_ctx_clean()
Radek Krejcidef50022016-02-01 16:38:32 +0100175 * - ly_ctx_destroy()
Radek Krejciee674072016-09-15 10:37:40 +0200176 * - lys_set_implemented()
Radek Krejci0ec51da2016-12-14 16:42:03 +0100177 * - lys_set_disabled()
178 * - lys_set_enabled()
Radek Krejcidef50022016-02-01 16:38:32 +0100179 */
180
181/**
182 * @page howtocontextdict Context Dictionary
183 *
184 * Context includes dictionary to store strings more effectively. The most of strings repeats quite often in schema
185 * as well as data trees. Therefore, instead of allocating those strings each time they appear, libyang stores them
186 * as records in the dictionary. The basic API to the context dictionary is public, so even a caller application can
187 * use the dictionary.
188 *
189 * To insert a string into the dictionary, caller can use lydict_insert() (adding a constant string) or
190 * lydict_insert_zc() (for dynamically allocated strings that won't be used by the caller after its insertion into
191 * the dictionary). Both functions return the pointer to the inserted string in the dictionary record.
192 *
193 * To remove (reference of the) string from the context dictionary, lydict_remove() is supposed to be used.
194 *
195 * \note Incorrect usage of the dictionary can break libyang functionality.
196 *
197 * \note API for this group of functions is described in the [XML Parser module](@ref dict).
198 *
199 * Functions List
200 * --------------
201 * - lydict_insert()
202 * - lydict_insert_zc()
203 * - lydict_remove()
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200204 */
205
206/**
207 * @page howtoschemas Schemas
208 *
Radek Krejcidef50022016-02-01 16:38:32 +0100209 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200210 * Schema is an internal libyang's representation of a YANG data model. Each schema is connected with
Radek Krejcidef50022016-02-01 16:38:32 +0100211 * its [context](@ref howtocontext) and loaded using [parser functions](@ref howtoschemasparsers). It means, that
212 * the schema cannot be created (nor changed) programmatically. In libyang, schemas are used only to
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200213 * access data model definitions.
214 *
Radek Krejcidef50022016-02-01 16:38:32 +0100215 * Schema tree nodes are able to hold private objects (via a pointer to a structure, function, variable, ...) used by
216 * a caller application. Such an object can be assigned to a specific node using lys_set_private() function.
217 * Note that the object is not freed by libyang when the context is being destroyed. So the caller is responsible
218 * for freeing the provided structure after the context is destroyed or the private pointer is set to NULL in
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200219 * appropriate schema nodes where the object was previously set. This can be automated via destructor function
220 * to free these private objects. The destructor is passed to the ly_ctx_destroy() function. On the other hand,
221 * freeing the object while the schema tree is still in use can lead to a segmentation fault.
Radek Krejcidef50022016-02-01 16:38:32 +0100222 *
223 * - @subpage howtoschemasparsers
224 * - @subpage howtoschemasfeatures
Radek Krejci16d64a52017-01-31 14:10:15 +0100225 * - @subpage howtoschemaextensions
Radek Krejcidef50022016-02-01 16:38:32 +0100226 * - @subpage howtoschemasprinters
227 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200228 * \note There are many functions to access information from the schema trees. Details are available in
229 * the [Schema Tree module](@ref schematree).
230 *
Radek Krejciee674072016-09-15 10:37:40 +0200231 * For information about difference between implemented and imported modules, see the
232 * [context description](@ref howtocontext).
233 *
Radek Krejcidef50022016-02-01 16:38:32 +0100234 * Functions List (not assigned to above subsections)
235 * --------------------------------------------------
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200236 * - lys_getnext()
Radek Krejcidef50022016-02-01 16:38:32 +0100237 * - lys_parent()
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200238 * - lys_module()
239 * - lys_node_module()
Radek Krejcidef50022016-02-01 16:38:32 +0100240 * - lys_set_private()
Radek Krejciee674072016-09-15 10:37:40 +0200241 * - lys_set_implemented()
Radek Krejci0ec51da2016-12-14 16:42:03 +0100242 * - lys_set_disabled()
243 * - lys_set_enabled()
Radek Krejcidef50022016-02-01 16:38:32 +0100244 */
245
246/**
247 * @page howtoschemasparsers Parsing Schemas
248 *
249 * Schema parser allows to read schema from a specific format. libyang supports the following schema formats:
250 *
251 * - YANG
252 *
Radek Krejci792f52f2017-02-28 16:36:31 +0100253 * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020) and
254 * [RFC 7951](http://tools.ietf.org/html/rfc7951) (so both YANG 1.0 and YANG 1.1 versions are supported).
Radek Krejcidef50022016-02-01 16:38:32 +0100255 *
Radek Krejcidef50022016-02-01 16:38:32 +0100256 * - YIN
257 *
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200258 * Alternative XML-based format to YANG - YANG Independent Notation. The details can be found in
Radek Krejci792f52f2017-02-28 16:36:31 +0100259 * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11) and
260 * [RFC 7951](http://tools.ietf.org/html/rfc7951#section-13).
Radek Krejcidef50022016-02-01 16:38:32 +0100261 *
Radek Krejci792f52f2017-02-28 16:36:31 +0100262 * When the [context](@ref howtocontext) is created, it already contains the following schemas, which
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200263 * are implemented internally by libyang:
Radek Krejci792f52f2017-02-28 16:36:31 +0100264 * - ietf-yang-metadata@2016-08-05
265 * - yang@2017-02-20
Radek Krejcidef50022016-02-01 16:38:32 +0100266 * - ietf-inet-types@2013-07-15
267 * - ietf-yang-types@2013-07-15
Radek Krejci792f52f2017-02-28 16:36:31 +0100268 * - ietf-yang-library@2016-06-21
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200269 *
Radek Krejci792f52f2017-02-28 16:36:31 +0100270 * The `yang` schema is the libyang's internal module to provide namespace and definitions of for various YANG
271 * attributes described in [RFC 7951](https://tools.ietf.org/html/rfc6243) (such as `insert` attribute for
272 * edit-config's data).
Radek Krejcidef50022016-02-01 16:38:32 +0100273 *
274 * Other schemas can be added to the context manually as described in [context page](@ref howtocontext) by the functions
275 * listed below. Besides the schema parser functions, it is also possible to use ly_ctx_load_module() which tries to
Michal Vaskof53187d2017-01-13 13:23:14 +0100276 * find the required schema automatically - using #ly_module_imp_clb or automatic search in working directory and in the
Radek Krejcidef50022016-02-01 16:38:32 +0100277 * context's searchpath.
278 *
279 * Functions List
280 * --------------
Radek Krejci722b0072016-02-01 17:09:45 +0100281 * - lys_parse_mem()
Radek Krejcidef50022016-02-01 16:38:32 +0100282 * - lys_parse_fd()
283 * - lys_parse_path()
Michal Vaskof53187d2017-01-13 13:23:14 +0100284 * - ly_ctx_set_module_imp_clb()
Radek Krejcidef50022016-02-01 16:38:32 +0100285 * - ly_ctx_load_module()
286 */
287
288/**
289 * @page howtoschemasfeatures YANG Features Manipulation
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200290 *
291 * The group of functions prefixed by \b lys_features_ are used to access and manipulate with the schema's
292 * features.
293 *
294 * The first two functions are used to access information about the features in the schema.
295 * lys_features_list() provides list of all features defined in the specific schema and its
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200296 * submodules. Optionally, it can also provide information about the state of all features.
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200297 * Alternatively, caller can use lys_features_state() function to get state of one specific
298 * feature.
299 *
300 * The remaining two functions, lys_features_enable() and lys_features_disable(), are used
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200301 * to enable and disable the specific feature (or all via the '`*`' value). By default, when the module
Radek Krejcidef50022016-02-01 16:38:32 +0100302 * is loaded by libyang parser, all features are disabled.
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200303 *
Radek Krejcidef50022016-02-01 16:38:32 +0100304 * To get know, if a specific schema node is currently disabled or enable, the lys_is_disabled() function can be used.
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200305 *
Radek Krejcidef50022016-02-01 16:38:32 +0100306 * Note, that the feature's state can affect some of the output formats (e.g. Tree format).
307 *
308 * Functions List
309 * --------------
310 * - lys_features_list()
311 * - lys_features_enable()
312 * - lys_features_disable()
313 * - lys_features_state()
314 * - lys_is_disabled()
315 */
316
317/**
Radek Krejci16d64a52017-01-31 14:10:15 +0100318 * @page howtoschemaextensions YANG Extensions Support
319 *
320 * YANG provides extensions as a mechanism how to add new statements into the language. Since they are very generic -
321 * extension instance can appear anywhere, they can contain any other YANG statement including extension instances and
322 * their specification has a form of the description text, it is very challenging for libyang to provide working and
323 * useful implementation. Therefore, you can reach some limitation regarding the extensions support, but the common
324 * use cases should be covered and supported.
325 *
326 * Since libyang does not understand human text, it is not possible to get the complete defintion of the extension from
Radek Krejci89db0592017-02-16 15:07:13 +0100327 * its description statement. Therefore, libyang allows the schema authors to provide @link lyext_plugin extension
328 * plugin@endlink that provides information from the extension description to libyang.
Radek Krejci16d64a52017-01-31 14:10:15 +0100329 *
330 * Here are some notes about the implementation of the particular YANG extensions features
331 *
332 * - Extension instance can appear anywhere
333 * This is completely supported. In addition, the extension plugins are allowed to provide callback function to
334 * check if the extension instance is actually allowed to be instantiated as a substatement of the particular node.
Radek Krejci89db0592017-02-16 15:07:13 +0100335 * In some case the extension instance is not stored in the libyang structures inside the statement it is
336 * instantiated since some statements (such as description, position and several others listed as #LYEXT_SUBSTMT) are
337 * not stored as a structure, but directly as a value. The extension instances of such statements are then actually
338 * stored besides the extension instances of the parent structure (e.g. in ::lys_type_bit in case of position's
339 * extension instances). These extension instances are indicated by the ::lys_ext_instance#insubstmt value which
340 * refers (sometimes in combination with ::lys_ext_instance#insubstmt_index) to the substatement where the particular
341 * extension is actually instantiated.
Radek Krejci16d64a52017-01-31 14:10:15 +0100342 *
343 * - Extension instance can contain any other YANG statement
Radek Krejci89db0592017-02-16 15:07:13 +0100344 * This is supported with exceptions - the list of YANG statements is defined as #LY_STMT enumeration with the
345 * description if the specific statement can appear as an extension instance substatement or if there is some
346 * limitation regarding its cardinality. It also specifies how the specific statement is stored in the extension
347 * instance (which data type or structure is used). In some cases, like `include` or `yang-version` statements, it
348 * make no sense to have them inside an extension instance, so they are not supported by libyang.
Radek Krejci16d64a52017-01-31 14:10:15 +0100349 *
Radek Krejci89db0592017-02-16 15:07:13 +0100350 * The list of allowed substatement for the specific extension instances is provided by the extension plugin. Besides
351 * the list of substatement, the plugin also specifies where the data are stored and the cardinality for each
352 * substatement. Other extension instances as an extension instance substatements are always allowed. Note, that if
353 * there is no extension plugin defined or if the list of the allowed substatements is empty, no substatement (except
354 * extension instances) is allowed.
355 *
356 * There are several extension types (enumerated as #LYEXT_TYPE) according to their purpose and content:
357 *
358 * - #LYEXT_FLAG - simple extension with no content (no substatement is allowed). The extension instance serves just as
359 * a flag with or without an argument and its value. The example of such an extension is NACM's __default-deny-write__
360 * or __default-deny-all__. This is the default type of extension for the case there is no extension plugin available
361 * for the specific extension. Extension instances of this type are represented as ::lys_ext_instance.
362 *
363 * - #LYEXT_COMPLEX - complex extension with content. The specific rules for the content and how it is stored in the
364 * extension instance structure is specified by the plugin. Extension instances of this type are represented as
365 * ::lys_ext_instance_complex.
366 *
367 * Note that the ::lys_ext_instance structure serves as a generic structure for all extension instances. In case the
368 * ::lys_ext_instance#ext_type is set to a different value than #LYEXT_FLAG, the structure can be cast to the particular
369 * extension instance structure to access the type-specific members.
Radek Krejci16d64a52017-01-31 14:10:15 +0100370 *
371 * Extension Plugins
372 * -----------------
373 * Extension plugins provide more detailed information about the extension in a understandable form for libyang. These
374 * information is usually provided in a text form in the extension's description statement. libyang provides several
375 * plugins for the common IETF extensions (NACM, Metadata, ...) that can be used as a code examples for other
376 * extensions.
377 *
Radek Krejci89db0592017-02-16 15:07:13 +0100378 * There are several types of extension plugins which corresponds to the extension types:
379 *
380 * - ::lyext_plugin - the plugin for a simple extensions of type #LYEXT_FLAG. The plugin is supposed to provide
381 * callbacks for:
382 * + @link lyext_check_position_clb checking extension position @endlink (if the extension instance can be instantiated
383 * in a particular parent)
384 * + @link lyext_check_inherit_clb deciding if the extension is supposed to be inherited @endlink
385 * (see #LYEXT_OPT_INHERIT). Note that the inherited extension instances are available in the libyang data
386 * structures, but they are not part of the schema so they are not printed into the schema output formats.
387 * + @link lyext_check_result_clb checking the result @endlink, the callback is called when the schema is completely
388 * parsed and all the data are available for the final (possibly complex) checking (or modification)
389 * - ::lyext_plugin_complex - the plugin for the complex extension instances (#LYEXT_COMPLEX). The structure extends
390 * the ::lyext_plugin structure by:
391 * + instance_size - the overall size of the ::lyext_plugin_complex structure to allocate.
392 * The substatement list is flexible array, so the size of the plugin structure depends on the content of the array.
393 * + substmt - the list of the allowed substatements to the extension instance, besides the substatement id, it
394 * also specifies its cardinality and the specific position in the ::lys_ext_instance_complex where the data are
395 * stored (as offset to the ::lys_ext_instance_complex#content member). The way how the data are stored is
396 * specified descriptions of #LY_STMT values.
397 *
398 * The plugins are loaded from the plugin directory (LIBDIR/libyang/) whenever a context is created. However, the list
399 * of plugins can be refreshed manually by lyext_load_plugins(). The plugin directory path can be change via the
400 * `LIBYANG_EXTENSIONS_PLUGINS_DIR` environment variable. Note, that no more available plugins are not removed, only
401 * the new plugins are loaded. Also note that availability of new plugins does not affect the current schemas in the
402 * contexts, they are applied only to the newly parsed schemas.
403 *
404 * The plugins list can be cleaned by lyext_clean_plugins(). However, since various contexts (respectively their
405 * schemas) can link to the plugins, the cleanup is successful only when there is no remaining context.
406 *
Radek Krejci792f52f2017-02-28 16:36:31 +0100407 * Metadata Support
408 * ----------------
409 * @anchor howtoschemametadata
410 *
411 * YANG Metadata annotations are defined in [RFC 7952](https://tools.ietf.org/html/rfc6243) as YANG extension. In
412 * practice, it allows to have XML attributes (there is also a special encoding for JSON) in YANG modeled data.
413 * libyang does not allow to have any XML attribute without the appropriate annotation definition describing the
414 * data as it is done e.g. for leafs. When an attribute without a matching annotation definition is found in the
415 * input data, it is silently dropped (with warning) or an error is reported in case the #LYD_OPT_STRICT parser
416 * option is provided to the [parser function](@ref howtodataparsers).
417 *
418 * There are some XML attributes, described by [YANG](https://tools.ietf.org/html/rfc7951) and
419 * [NETCONF](https://tools.ietf.org/html/rfc6241) specifications, which are not defined as annotations, but libyang
420 * implements them this way. In case of attributes in the YANG namespace (`insert`, `value` and `key` attributes
421 * for the NETCONF edit-config operation), they are defined in special libyang's internal module `yang`, which is
422 * available in each context and the content of this schema can be printed via
423 * [schema printers](@ref howtoschemasprinters).
424 *
425 * In case of the attributes described in [NETCONF specification](https://tools.ietf.org/html/rfc6241), the libyang's
426 * annotations structures are hidden and cannot be printed despite, internally, they are part of the `ietf-netconf`'s
427 * schema structure. Therefore, these attributes are available only when the `ietf-netconf` schema is loaded in the
428 * context. The definitions of these annotations are as follows:
429 *
430 * md:annotation operation {
431 * type enumeration {
432 * enum merge;
433 * enum replace;
434 * enum create;
435 * enum delete;
436 * enum remove;
437 * }
438 * }
439 *
440 * md:annotation type {
441 * type enumeration {
442 * enum subtree;
443 * enum xpath {
444 * if-feature "nc:xpath";
445 * }
446 * }
447 * }
448 *
449 * md:annotation select {
450 * type string;
451 * }
452 *
453 * Note, that, following the specification,
454 * - the `type` and `select` XML attributes are supposed to be unqualified (without namespace) and that
455 * - the `select`'s content is XPath and it is internally transformed by libyang into the format where the
456 * XML namespace prefixes are replaced by the YANG module names.
457 *
Radek Krejci16d64a52017-01-31 14:10:15 +0100458 * Functions List
459 * --------------
Radek Krejci16d64a52017-01-31 14:10:15 +0100460 * - lys_ext_instance_presence()
461 * - lys_ext_instance_substmt()
Radek Krejci89db0592017-02-16 15:07:13 +0100462 * - lyext_load_plugins()
463 * - lyext_clean_plugins()
Radek Krejci16d64a52017-01-31 14:10:15 +0100464 */
465
466/**
Radek Krejcidef50022016-02-01 16:38:32 +0100467 * @page howtoschemasprinters Printing Schemas
468 *
469 * Schema printers allows to serialize internal representation of a schema module in a specific format. libyang
470 * supports the following schema formats for printing:
471 *
472 * - YANG
473 *
Radek Krejci792f52f2017-02-28 16:36:31 +0100474 * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020) and
475 * [RFC 7951](http://tools.ietf.org/html/rfc7951) (so both YANG 1.0 and YANG 1.1 versions are supported).
Radek Krejcidef50022016-02-01 16:38:32 +0100476 *
477 * - YIN
478 *
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200479 * Alternative XML-based format to YANG - YANG Independent Notation. The details can be found in
Radek Krejci792f52f2017-02-28 16:36:31 +0100480 * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11) and
481 * [RFC 7951](http://tools.ietf.org/html/rfc7951#section-13).
Radek Krejcidef50022016-02-01 16:38:32 +0100482 *
Radek Krejcidef50022016-02-01 16:38:32 +0100483 * - Tree
484 *
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200485 * Simple tree structure of the module where each node is printed as:
486 *
487 * <status> <flags> <name> <opts> <type> <if-features>
488 *
489 * - `<status>` is one of:
490 * - `+` for current
491 * - `x` for deprecated
492 * - `o` for obsolete
493 *
494 * - `<flags>` is one of:
495 * - `rw` for configuration data
496 * - `ro` for status data
497 * - `-x` for RPCs
498 * - `-n` for Notification
499 *
500 * - `<name>` is the name of the node
501 * - `(<name>)` means that the node is a choice node
502 * - `:(<name>)` means that the node is a case node
503 * - if the node is augmented into the tree from another module, it is printed with the module name as
504 * `<module-name>:<name>`.
505 *
506 * - `<opts>` is one of:
507 * - `?` for an optional leaf or choice
508 * - `!` for a presence container
509 * - `*` for a leaf-list or list
510 * - `[<keys>]` for a list's keys
511 *
512 * - `<type>` is the name of the type for leafs and leaf-lists
513 * - if there is a default value defined, it is printed within angle brackets `<default-value>`
514 * - if the type is a leafref, the type is printed as -> TARGET`
515 *
516 * - `<if-features>` is the list of features this node depends on, printed within curly brackets and
517 * a question mark `{...}?`
518 *
Radek Krejcidef50022016-02-01 16:38:32 +0100519 *
520 * - Info
521 *
522 * Detailed information about the specific node in the schema tree.
523 * It allows to print information not only about a specific module, but also about its specific part:
524 *
525 * - absolute-schema-nodeid
526 *
527 * e.g. \a `/modules/module-set-id` in \a `ietf-yang-library` module
528 *
529 * - <b>typedef/</b>typedef-name
530 *
531 * e.g. \a `typedef/revision-identifier` in \a `ietf-yang-library` module
532 *
533 * - <b>feature/</b>feature-name
534 *
535 * e.g. \a `feature/ssh` in \a `ietf-netconf-server` module
536 *
537 * - <b>grouping/</b>grouping-name/descendant-schema-nodeid
538 *
539 * e.g. \a `grouping/module` or \a `grouping/module/module/submodules` in \a `ietf-yang-library` module
540 *
541 * - <b>type/</b>leaf-or-leaflist
542 *
543 * e.g. \a `type/modules/module-set-id` in \a `ietf-yang-library` module
544 *
545 * Printer functions allow to print to the different outputs including a callback function which allows caller
546 * to have a full control of the output data - libyang passes to the callback a private argument (some internal
547 * data provided by a caller of lys_print_clb()), string buffer and number of characters to print. Note that the
548 * callback is supposed to be called multiple times during the lys_print_clb() execution.
549 *
550 * Functions List
551 * --------------
552 * - lys_print_mem()
553 * - lys_print_fd()
554 * - lys_print_file()
555 * - lys_print_clb()
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200556 */
557
558/**
559 * @page howtodata Data Instances
Radek Krejci26715a42015-07-29 14:10:45 +0200560 *
Radek Krejcidef50022016-02-01 16:38:32 +0100561 * All data nodes in data trees are connected with their schema node - libyang is not able to represent data of an
562 * unknown schema.
563 *
Michal Vasko42aa0ab2016-10-25 15:09:32 +0200564 * Connected to the aforementioned, it is important to mention that there are several kinds of data trees libyang
565 * can work with. Except for a standard full data tree and configuration data tree, there are trees specific for use
566 * in NETCONF, which are \<get\> or \<get-config\> replies, \<edit-config\> input content, generic RPC/action request,
567 * RPC/action reply, or a notification.
568 *
569 * Special care is needed when working with action input and RPC/action output, because in these cases the libyang data
570 * tree does not match the actual data tree NETCONF expects.
571 *
572 * <b>Action input</b> differentiates from a standard RPC that the child of \<rpc\> element is not the specific RPC
573 * request being sent, but a special \<action\> element in the base YANG namespace. It is expected to be present when
574 * parsing an action input and can optionally be included when the action is printed.
575 *
576 * As for <b>RPC output</b>, NETCONF expects the output parameters as direct children of the \<rpc-reply\> element.
577 * However, libyang encapsulates these parameters in the specific RPC request container. Same as before, it is expected
578 * to be without this container when parsing and can be printed out.
579 *
580 * Lastly, <b>action output</b> is almost similar to RPC output and in NETCONF you actually cannot distinguish them,
581 * but in case of action output, libyang puts all the output parameters under the action container, which is also
582 * just a child to all the schema tree ancestors up to the schema top-level, just like in an action input. Same applies
583 * even in this case, parsed data should be only the output parameters, you can decide how to print it.
584 *
585 * So, you do not have to use any special flag when you want to print the data tree the way libyang internally stores
586 * it, although you will not be able to parse it back, as was mentioned in the paragraphs above. To print data in the
587 * way NETCONF and libyang expects them to be, use #LYP_NETCONF flag for any printing function.
588 *
Michal Vasko1ec579e2016-09-13 11:24:28 +0200589 * Please, continue reading a specific subsection or go through all the subsections if you are a new user of libyang.
Radek Krejcidef50022016-02-01 16:38:32 +0100590 *
591 * - @subpage howtodataparsers
592 * - @subpage howtodatamanipulators
Michal Vasko1ec579e2016-09-13 11:24:28 +0200593 * - @subpage howtodatavalidation
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200594 * - @subpage howtodatawd
Radek Krejcidef50022016-02-01 16:38:32 +0100595 * - @subpage howtodataprinters
596 *
597 * \note API for this group of functions is described in the [Data Instances module](@ref datatree).
598 *
599 * Functions List (not assigned to above subsections)
600 * --------------------------------------------------
Michal Vaskof06fb5b2016-09-08 10:05:56 +0200601 * - lyd_find_instance()
602 * - lyd_find_xpath()
Radek Krejciae1c3b12016-09-20 16:30:32 +0200603 * - lyd_leaf_type()
Radek Krejcidef50022016-02-01 16:38:32 +0100604 */
605
606/**
607 * @page howtodataparsers Parsing Data
608 *
609 * Data parser allows to read instances from a specific format. libyang supports the following data formats:
610 *
611 * - XML
612 *
613 * Original data format used in NETCONF protocol. XML mapping is part of the YANG specification
614 * ([RFC 6020](http://tools.ietf.org/html/rfc6020)).
615 *
616 * - JSON
617 *
618 * The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG
619 * can be found in [this draft](https://tools.ietf.org/html/draft-ietf-netmod-yang-json-05).
620 *
621 * Besides the format of input data, the parser functions accepts additional [options](@ref parseroptions) to specify
622 * how the input data should be processed.
623 *
624 * In contrast to the schema parser, data parser also accepts empty input data if such an empty data tree is valid
625 * according to the schemas in the libyang context.
626 *
Michal Vasko346b5f32017-03-07 10:42:40 +0100627 * If a node from a schema, which is not present in the context or is not implemented, is parsed, a callback set by
628 * ly_ctx_set_module_data_clb() is called and this way the application is given the opportunity to add this schema into
629 * the context or change its conformance before the parsing would fail.
Michal Vaskof53187d2017-01-13 13:23:14 +0100630 *
Radek Krejcidef50022016-02-01 16:38:32 +0100631 * In case of XML input data, there is one additional way to parse input data. Besides parsing the data from a string
632 * in memory or a file, caller is able to build an XML tree using [libyang XML parser](@ref howtoxml) and then use
633 * this tree (or a part of it) as input to the lyd_parse_xml() function.
634 *
635 * Functions List
636 * --------------
Radek Krejci722b0072016-02-01 17:09:45 +0100637 * - lyd_parse_mem()
Radek Krejcidef50022016-02-01 16:38:32 +0100638 * - lyd_parse_fd()
639 * - lyd_parse_path()
640 * - lyd_parse_xml()
641 */
642
643/**
644 * @page howtodatamanipulators Manipulating Data
645 *
646 * There are many functions to create or modify an existing data tree. You can add new nodes, reconnect nodes from
647 * one tree to another (or e.g. from one list instance to another) or remove nodes. The functions doesn't allow you
648 * to put a node to a wrong place (by checking the module), but not all validation checks can be made directly
649 * (or you have to make a valid change by multiple tree modifications) when the tree is being changed. Therefore,
Michal Vasko58f74f12016-03-24 13:26:06 +0100650 * there is lyd_validate() function supposed to be called to make sure that the current data tree is valid. If
651 * working with RPCs, they are invalid also in case the data nodes are not ordered according to the schema, which
652 * you can fix easily with lyd_schema_sort(). Note, that not performing validation after some data tree changes
Michal Vasko299f9832017-01-06 13:29:22 +0100653 * can cause failure of various libyang functions later. All functions performing data tree changes are marked
654 * with the __PARTIAL CHANGE__ flag in their documentation meaning they leave at least partly non-validated data tree.
Radek Krejcidef50022016-02-01 16:38:32 +0100655 *
Michal Vasko0f14ba62016-03-21 15:38:11 +0100656 * Creating data is generally possible in two ways, they can be combined. You can add nodes one-by-one based on
Michal Vasko1ec579e2016-09-13 11:24:28 +0200657 * the node name and/or its parent (lyd_new(), \b lyd_new_anydata_*(), lyd_new_leaf(), and their output variants) or
Michal Vasko58f74f12016-03-24 13:26:06 +0100658 * address the nodes using a simple XPath addressing (lyd_new_path()). The latter enables to create a whole path
659 * of nodes, requires less information about the modified data, and is generally simpler to use. The path format
660 * specifics can be found [here](@ref howtoxpath).
Michal Vasko0f14ba62016-03-21 15:38:11 +0100661 *
Michal Vasko3c126822016-09-22 13:48:42 +0200662 * Working with two data subtrees can also be performed two ways. Usually, you would use lyd_insert*() functions.
663 * They are generally meant for simple inserts of a node into a data tree. For more complicated inserts and when
664 * merging 2 trees use lyd_merge(). It offers additional options and is basically a more powerful insert.
Michal Vasko45fb2822016-04-18 13:32:17 +0200665 *
Radek Krejcidef50022016-02-01 16:38:32 +0100666 * Also remember, that when you are creating/inserting a node, all the objects in that operation must belong to the
667 * same context.
668 *
669 * Modifying the single data tree in multiple threads is not safe.
670 *
671 * Functions List
672 * --------------
673 * - lyd_dup()
Radek Krejciab80e3a2017-01-09 13:07:31 +0100674 * - lyd_dup_to_ctx()
Radek Krejcidef50022016-02-01 16:38:32 +0100675 * - lyd_change_leaf()
676 * - lyd_insert()
Radek Krejcidb6b1662016-09-15 10:40:16 +0200677 * - lyd_insert_sibling()
Radek Krejcidef50022016-02-01 16:38:32 +0100678 * - lyd_insert_before()
679 * - lyd_insert_after()
680 * - lyd_insert_attr()
Michal Vasko45fb2822016-04-18 13:32:17 +0200681 * - lyd_merge()
Radek Krejciab80e3a2017-01-09 13:07:31 +0100682 * - lyd_merge_to_ctx()
Radek Krejcidef50022016-02-01 16:38:32 +0100683 * - lyd_new()
Michal Vasko0845b112016-09-08 10:07:08 +0200684 * - lyd_new_anydata()
Radek Krejcidef50022016-02-01 16:38:32 +0100685 * - lyd_new_leaf()
Michal Vaskof5299282016-03-16 13:32:02 +0100686 * - lyd_new_path()
Michal Vasko0ba46152016-05-11 14:16:55 +0200687 * - lyd_new_output()
Michal Vasko0845b112016-09-08 10:07:08 +0200688 * - lyd_new_output_anydata()
Michal Vasko0ba46152016-05-11 14:16:55 +0200689 * - lyd_new_output_leaf()
Michal Vaskoae5a53e2017-01-05 10:33:41 +0100690 * - lyd_list_pos()
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200691 * - lyd_schema_sort()
Radek Krejcidef50022016-02-01 16:38:32 +0100692 * - lyd_unlink()
693 * - lyd_free()
694 * - lyd_free_attr()
695 * - lyd_free_withsiblings()
Michal Vasko1ec579e2016-09-13 11:24:28 +0200696 */
697
698/**
699 * @page howtodatavalidation Validating Data
700 *
701 * By default, the represented data are supposed to represent a full YANG datastore content. So if a schema declares
702 * some mandatory nodes, despite configuration or status, the data are supposed to be present in the data tree being
703 * loaded or validated. However, it is possible to specify other kinds of data (see @ref parseroptions) allowing some
704 * exceptions to the validation process.
705 *
706 * Data validation is performed implicitly to the input data processed by the parser (\b lyd_parse_*() functions) and
707 * on demand via the lyd_validate() function. The lyd_validate() is supposed to be used when a (complex or simple)
708 * change is done on the data tree (via a combination of \b lyd_change_*(), \b lyd_insert*(), \b lyd_new*(),
709 * lyd_unlink() and lyd_free() functions).
710 *
Michal Vaskof53187d2017-01-13 13:23:14 +0100711 * Part of data validation is resolving leafrefs and instance-identifiers. Leafrefs are resolved only when a change occured
712 * in the data tree that could have broken the link. However, as instance-identifiers can point to any node whatsoever
713 * without an import, it would not be effective to store metadata as in the case of leafrefs. That is why they are resolved
714 * during every validation. Also, for the same reason, it can easily happen that when parsing/validating data with
715 * an instance-identifier, it will target a remote node, whose schema is not currently present in the context. To handle
716 * this case, a callback should be set using ly_ctx_set_module_data_clb(), which can load the schema when required.
717 *
Michal Vasko1ec579e2016-09-13 11:24:28 +0200718 * Must And When Conditions Accessible Tree
719 * ----------------------------------------
720 *
721 * In YANG 1.1, there can be \b must and/or \b when expressions in RPC/action input or output, or in notifications that
722 * require access to the configuration datastore and/or state data. Normally, when working with any of the aforementioned
723 * data trees, they must contain only the RPC/action/notification itself, without any additional configuration or state
724 * data. So how can then these conditions be verified during validation?
725 *
726 * There is an option to pass this additional data tree to all the functions that perform \b must and \b when condition
Michal Vasko3c4cf902017-01-03 14:43:38 +0100727 * checking (\b lyd_parse_*() and lyd_validate()). Also, there are 2 flags of \b struct lys_node that
728 * mark schema nodes that include paths that require foreign nodes (outside their subtree) for their evaluation. #LYS_XPATH_DEP
729 * marks nodes with such must and/or when expressions, #LYS_LEAFREF_DEP with such a leafref.
Michal Vasko1ec579e2016-09-13 11:24:28 +0200730 * The subtree root is always the particular operation data node (for RPC it is the RPC data node and all
731 * the input or output nodes as its children and similarly for action and notification). Note that for action and
732 * not-top-level notification this means that all their parents are not considered as belonging to their subtree even though
733 * they are included in their data tree and must be present for the operation validation to pass. The reason for this is that if
734 * there are any lists in those parents, we cannot know if there are not some other instances of them in the standard
735 * data tree in addition to the one used in the action/notification invocation.
736 *
737 * There were 2 ways of using this mechanism envisioned (explained below), but you can combine or modify them.
738 *
739 * ### Fine-grained Data Retrieval ###
740 *
741 * This approach is recommended when you do not maintain a full configuration data tree with state data at all times.
742 *
743 * Firstly, you should somehow learn that the operation data tree you are currently working with includes some schema
744 * node instances that have conditions that require foreign data. You can either know this about every operation beforehand
Michal Vasko3c4cf902017-01-03 14:43:38 +0100745 * or you go through all the schema nodes looking for the flags #LYS_XPATH_DEP and #LYS_LEAFREF_DEP. Then you should use lys_node_xpath_atomize()
Michal Vasko1ec579e2016-09-13 11:24:28 +0200746 * to retrieve all XPath condition dependencies (in the form of schema nodes) outside the operation subtree. You will likely
747 * want to use the flag #LYXP_NO_LOCAL to get rid of all the nodes from inside the subtree (you should already have those).
748 * The last thing to do is to build a data tree that includes at least all the instances of the nodes obtained from lys_node_xpath_atomize()
749 * (it will be expected). Then you pass this tree to the validation and it should now have access to all the nodes that
750 * can potentially affect the XPath evaluation and no other.
751 *
752 * ### Maintaining Configuration And State Data Tree ###
753 *
754 * If you have a full data tree with state data available for the validation process then it is quite simple (compared
755 * to the first approach). You can simply always pass it to validation of these operations and in cases it is not required
756 * (no nodes with conditions traversing foreign nodes) only a negligible amount of redundant work is performed and you can
757 * skip the process of learning whether it is required or not.
758 *
759 * Functions List
760 * --------------
Radek Krejcidef50022016-02-01 16:38:32 +0100761 * - lyd_validate()
762 */
763
764/**
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200765 * @page howtodatawd Default Values
766 *
Radek Krejcidb6b1662016-09-15 10:40:16 +0200767 * libyang provides support for work with default values as defined in [RFC 6243](https://tools.ietf.org/html/rfc6243).
Radek Krejci46180b52016-08-31 16:01:32 +0200768 * This document defines 4 modes for handling default nodes in a data tree, libyang adds the fifth mode:
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200769 * - \b explicit - Only the explicitly set configuration data. But in the case of status data, missing default
Radek Krejci46180b52016-08-31 16:01:32 +0200770 * data are added into the tree. In libyang, this mode is represented by #LYP_WD_EXPLICIT option.
771 * - \b trim - Data nodes containing the schema default value are removed. This mode is applied using #LYP_WD_TRIM option.
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200772 * - \b report-all - All the missing default data are added into the data tree. This mode is represented by
Radek Krejci46180b52016-08-31 16:01:32 +0200773 * #LYP_WD_ALL option.
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200774 * - \b report-all-tagged - In this case, all the missing default data are added as in case of the `report-all` mode,
775 * but additionally all the nodes (existing as well as added) containing the schema default value
Radek Krejci46180b52016-08-31 16:01:32 +0200776 * are tagged (see the note below). libyang uses #LYP_WD_ALL_TAG option for this mode.
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200777 * - \b report-implicit-tagged - The last mode is similar to the previous one, except only the added nodes are tagged.
Radek Krejci46180b52016-08-31 16:01:32 +0200778 * This is the libyang's extension and it is represented by #LYP_WD_IMPL_TAG option.
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200779 *
Radek Krejci46180b52016-08-31 16:01:32 +0200780 * libyang automatically adds/maintain the default nodes when a data tree is being parsed or validated. Note, that in a
781 * modified data tree (via e.g. lys_insert() or lys_free()), some of the default nodes can be missing or they can be
782 * present by mistake. Such a data tree is again corrected during the next lyd_validate() call.
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200783 *
Radek Krejci46180b52016-08-31 16:01:32 +0200784 * The implicit (default) nodes, created by libyang, are marked with the ::lyd_node#dflt flag which applies to the
Radek Krejcid3cfbc92016-09-15 10:39:33 +0200785 * leafs and leaf-lists. In case of containers, the flag means that the container holds only a default node(s) or it
786 * is an empty container (according to YANG 1.1 spec, all such containers are part of the accessible data tree).
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200787 *
Radek Krejci46180b52016-08-31 16:01:32 +0200788 * The presence of the default nodes during the data tree lifetime is affected by the LYD_OPT_ flag used to
789 * parse/validate the tree:
790 * - #LYD_OPT_DATA - all the default nodes are present despite they are configuration or status nodes
791 * - #LYD_OPT_CONFIG - only the configuration data nodes are added into the tree
792 * - #LYD_OPT_GET, #LYD_OPT_GETCONFIG, #LYD_OPT_EDIT - no default nodes are added
793 * - #LYD_OPT_RPC, #LYD_OPT_RPCREPLY, #LYD_OPT_NOTIF - the default nodes from the particular subtree are added
794 *
Radek Krejcidb6b1662016-09-15 10:40:16 +0200795 * The with-default modes described above are supported when the data tree is being printed with the
Radek Krejci46180b52016-08-31 16:01:32 +0200796 * [LYP_WD_ printer flags](@ref printerflags). Note, that in case of #LYP_WD_ALL_TAG and #LYP_WD_IMPL_TAG modes,
797 * the XML/JSON attributes are printed only if the context includes the ietf-netconf-with-defaults schema. Otherwise,
Radek Krejcid3cfbc92016-09-15 10:39:33 +0200798 * these modes have the same result as #LYP_WD_ALL. The presence of empty containers (despite they were added explicitly
799 * or implicitly as part of accessible data tree) depends on #LYP_KEEPEMPTYCONT option.
Radek Krejci46180b52016-08-31 16:01:32 +0200800 *
801 * To get know if the particular leaf or leaf-list node contains default value (despite implicit or explicit), you can
Radek Krejcidb6b1662016-09-15 10:40:16 +0200802 * use lyd_wd_default() function.
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200803 *
804 * Functions List
805 * --------------
Radek Krejci46180b52016-08-31 16:01:32 +0200806 * - lyd_wd_default()
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200807 *
808 * - lyd_parse_mem()
809 * - lyd_parse_fd()
810 * - lyd_parse_path()
811 * - lyd_parse_xml()
812 * - lyd_validate()
Radek Krejci46180b52016-08-31 16:01:32 +0200813 * - lyd_print_mem()
814 * - lyd_print_fd()
815 * - lyd_print_file()
816 * - lyd_print_clb()
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200817 */
818
819/**
Radek Krejcidef50022016-02-01 16:38:32 +0100820 * @page howtodataprinters Printing Data
821 *
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200822 * Data printers allows to serialize internal representation of a data tree in a specific format. libyang
823 * supports the following data formats for printing:
Radek Krejcidef50022016-02-01 16:38:32 +0100824 *
825 * - XML
826 *
827 * Basic format as specified in rules of mapping YANG modeled data to XML in
828 * [RFC 6020](http://tools.ietf.org/html/rfc6020). It is possible to specify if
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200829 * the indentation (formatting) will be used (by #LYP_FORMAT @ref printerflags "printer option").
Radek Krejcidef50022016-02-01 16:38:32 +0100830 *
831 * - JSON
832 *
833 * The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200834 * can be found in [this draft](https://tools.ietf.org/html/draft-ietf-netmod-yang-json-05).It is possible to specify
835 * if the indentation (formatting) will be used (by #LYP_FORMAT @ref printerflags "printer option").
Radek Krejcidef50022016-02-01 16:38:32 +0100836 *
837 * Printer functions allow to print to the different outputs including a callback function which allows caller
838 * to have a full control of the output data - libyang passes to the callback a private argument (some internal
839 * data provided by a caller of lyd_print_clb()), string buffer and number of characters to print. Note that the
840 * callback is supposed to be called multiple times during the lyd_print_clb() execution.
841 *
Radek Krejci46180b52016-08-31 16:01:32 +0200842 * To print the data tree with default nodes according to the with-defaults capability defined in
843 * [RFC 6243](https://tools.ietf.org/html/rfc6243), check the [page about the default values](@ref howtodatawd).
844 *
Michal Vasko42aa0ab2016-10-25 15:09:32 +0200845 * Also, to print the data in NETCONF format, use the #LYP_NETCONF flag. More information can be found on the page
846 * @ref howtodata.
847 *
Radek Krejcidef50022016-02-01 16:38:32 +0100848 * Functions List
849 * --------------
850 * - lyd_print_mem()
851 * - lyd_print_fd()
852 * - lyd_print_file()
853 * - lyd_print_clb()
854 */
855
856/**
Radek Krejcib50551c2016-04-19 09:15:38 +0200857 * @page howtoxpath XPath Addressing
858 *
859 * Internally, XPath evaluation is performed on \b when and \b must conditions in the schema. For that almost
Michal Vasko88aae042016-09-08 08:57:09 +0200860 * a full XPath 1.0 evaluator was implemented except that only node sets are returned. This XPath implementation
Michal Vaskof06fb5b2016-09-08 10:05:56 +0200861 * is available on data trees by calling lyd_find_xpath() and on schema trees by calling lys_find_xpath().
Michal Vasko46a4bf92016-09-08 08:23:49 +0200862 * This XPath conforms to the YANG specification (RFC 6020 section 6.4). Some useful examples:
Michal Vasko8e627692016-04-19 12:15:47 +0200863 *
Michal Vaskoebea7012016-04-19 14:15:22 +0200864 * - get all top-level nodes of the __module-name__
865 *
866 * /module-name:*
867 *
868 * - get all the descendants of __container__ (excluding __container__)
869 *
870 * /module-name:container//\asterisk
871 *
872 * - get __list__ instance with __key1__ of value __1__ and __key2__ of value __2__ (this can return more __list__ instances if there are more keys than __key1__ and __key2__)
873 *
874 * /module-name:container/list[key1='1'][key2='2']
875 *
876 * - get __leaf-list__ instance with the value __val__
877 *
878 * /module-name:container/leaf-list[.='val']
879 *
880 * - get __aug-leaf__, which was added to __module-name__ from an augment module __augment-module__
881 *
882 * /module-name:container/container2/augment-module:aug-cont/aug-leaf
883 *
Radek Krejcib50551c2016-04-19 09:15:38 +0200884 *
885 * A very small subset of this full XPath is recognized by lyd_new_path(). Basically, only a relative or absolute
Michal Vasko58c2aab2017-01-05 10:02:05 +0100886 * path can be specified to identify a new data node. However, lists must be identified by either all their keys and created
887 * with all of them or using their relative position on their level starting from 1, so for those cases predicates are
Michal Vaskoae5a53e2017-01-05 10:33:41 +0100888 * allowed. List positions can be learned using lyd_list_pos(). Key predicates must be ordered the way the keys are
889 * ordered and all the keys must be specified. Every predicate includes a single key with its value. If an instance
890 * with such particular set of keys or with such relative position does not exist or no predicate is specified, list
891 * instance is created. Optionally, leaves and leaf-lists can have predicates specifying their value in the path itself.
892 * All these paths are valid XPath expressions. Example:
Radek Krejcib50551c2016-04-19 09:15:38 +0200893 *
Michal Vasko1acf8502016-05-05 09:14:07 +0200894 * /ietf-yang-library:modules-state/module[name='ietf-yang-library'][revision='']/conformance[.='implement']
Michal Vasko58c2aab2017-01-05 10:02:05 +0100895 * /ietf-yang-library:modules-state/module[1]/conformance[.='implement']
Radek Krejcib50551c2016-04-19 09:15:38 +0200896 *
897 * Almost the same XPath is accepted by ly_ctx_get_node(). The difference is that it is not used on data, but schema,
898 * which means there are no key values and only one node matches one path. In effect, lists do not have to have any
899 * predicates. If they do, they do not need to have all the keys specified and if values are included, they are ignored.
900 * Nevertheless, any such expression is still a valid XPath, but can return more nodes if executed on a data tree.
901 * Examples (all returning the same node):
902 *
903 * /ietf-yang-library:modules-state/module/submodules
904 * /ietf-yang-library:modules-state/module[name]/submodules
905 * /ietf-yang-library:modules-state/module[name][revision]/submodules
906 * /ietf-yang-library:modules-state/module[name='ietf-yang-library'][revision]/submodules
907 *
908 * Also, `choice`, `case`, `input`, and `output` nodes need to be specified and cannot be skipped in schema XPaths. Use
Michal Vasko8d26e5c2016-09-08 10:03:49 +0200909 * lys_find_xpath() if you want to search based on a data XPath.
Radek Krejcib50551c2016-04-19 09:15:38 +0200910 *
911 * Also note, that in all cases the node's prefix is specified as the name of the appropriate YANG schema. Any node
912 * can be prefixed by the module name. However, if the prefix is omitted, the module name is inherited from the previous
913 * (parent) node. It means, that the first node in the path is always supposed to have a prefix.
914 *
915 * Functions List
916 * --------------
Michal Vaskof06fb5b2016-09-08 10:05:56 +0200917 * - lyd_find_xpath()
918 * - lys_find_xpath()
Radek Krejcib50551c2016-04-19 09:15:38 +0200919 * - lyd_new_path()
920 * - ly_ctx_get_node()
Radek Krejcib50551c2016-04-19 09:15:38 +0200921 */
922
923/**
Radek Krejcidef50022016-02-01 16:38:32 +0100924 * @page howtoxml libyang XML Support
925 *
Radek Krejcib50551c2016-04-19 09:15:38 +0200926 * libyang XML parser is able to parse XML documents. The main purpose is to load data modeled by YANG. However, it can
927 * be used as a standalone XML parser with the following limitations in comparison to a full-featured XML parsers:
Radek Krejcidef50022016-02-01 16:38:32 +0100928 * - comments are ignored
929 * - Doctype declaration is ignored
930 * - CData sections are ignored
931 * - Process Instructions (PI) are ignored
932 *
933 * The API is designed to almost only read-only access. You can simply load XML document, go through the tree as
934 * you wish and dump the tree to an output. The only "write" functions are lyxml_free() and lyxml_unlink() to remove
935 * part of the tree or to unlink (separate) a subtree.
936 *
Radek Krejcib50551c2016-04-19 09:15:38 +0200937 * XML parser is used internally by libyang for parsing YIN schemas and data instances in XML format.
Radek Krejcidef50022016-02-01 16:38:32 +0100938 *
939 * \note API for this group of functions is described in the [XML Parser module](@ref xmlparser).
940 *
941 * Functions List
942 * --------------
Radek Krejci722b0072016-02-01 17:09:45 +0100943 * - lyxml_parse_mem()
944 * - lyxml_parse_path()
Radek Krejcidef50022016-02-01 16:38:32 +0100945 * - lyxml_get_attr()
946 * - lyxml_get_ns()
Radek Krejci722b0072016-02-01 17:09:45 +0100947 * - lyxml_print_mem()
948 * - lyxml_print_fd()
949 * - lyxml_print_file()
950 * - lyxml_print_clb()
Radek Krejcidef50022016-02-01 16:38:32 +0100951 * - lyxml_unlink()
952 * - lyxml_free()
953 */
954
955/**
956 * @page howtothreads libyang in Threads
957 *
Radek Krejcib50551c2016-04-19 09:15:38 +0200958 * libyang can be used in multithreaded applications keeping in mind the following rules:
Radek Krejcidef50022016-02-01 16:38:32 +0100959 * - libyang context manipulation (adding new schemas) is not thread safe and it is supposed to be done in a main
Radek Krejcib50551c2016-04-19 09:15:38 +0200960 * thread before any other work with context, schemas or data instances. Destroying the context is supposed to
Michal Vaskoe77dc992017-01-18 12:09:42 +0100961 * be done when no other thread accesses context, schemas nor data trees,
962 * - data parser (\b lyd_parse*() functions) can be used simultaneously in multiple threads (also the returned
963 * #ly_errno is thread safe),
964 * - data manipulation (lyd_new(), lyd_insert(), lyd_unlink(), lyd_free() and many other
965 * functions) a single data tree is not thread safe,
966 * - data printing of a single data tree is thread-safe.
Radek Krejci26715a42015-07-29 14:10:45 +0200967 */
Radek Krejci94ca54b2015-07-08 15:48:47 +0200968
Radek Krejcida04f4a2015-05-21 12:54:09 +0200969/**
Radek Krejci26715a42015-07-29 14:10:45 +0200970 *
971 * @page howtologger Logger
972 *
973 * There are 4 verbosity levels defined as ::LY_LOG_LEVEL. The level can be
974 * changed by the ly_verb() function. By default, the verbosity level is
975 * set to #LY_LLERR value.
976 *
Radek Krejcib50551c2016-04-19 09:15:38 +0200977 * When an error is encountered, the error message and error number are stored for
978 * later use. Caller is able to access the last error message via ly_errmsg() and the
979 * corresponding last error code via #ly_errno. If that was a validation error (#ly_errno
980 * is set to #LY_EVALID), also validation error code (via #ly_vecode) and path to the
981 * error node (via ly_errpath()) are available.
982 *
983 * For some specific cases, a YANG schema can define error message and/or error tag (mainly for
Michal Vaskoebea7012016-04-19 14:15:22 +0200984 * use in NETCONF). If a message is set, it is provided via ly_errmsg(). If a tag is set in schema,
Radek Krejcib50551c2016-04-19 09:15:38 +0200985 * it is available via ly_erraptag() (if not set, the returned string is empty).
986 *
Michal Vaskoebea7012016-04-19 14:15:22 +0200987 * By default, all libyang messages are printed to `stderr`. However, the caller is able to set their own logging
Radek Krejcib50551c2016-04-19 09:15:38 +0200988 * callback function. In that case, instead of printing messages, libyang passes error level, message and path
989 * (if any) to the caller's callback function. In case of error level, the message and path are still
990 * automatically stored and available via the functions and macros described above.
Radek Krejci26715a42015-07-29 14:10:45 +0200991 *
Radek Krejcidef50022016-02-01 16:38:32 +0100992 * \note API for this group of functions is described in the [logger module](@ref logger).
993 *
994 * Functions List
995 * --------------
996 * - ly_verb()
997 * - ly_set_log_clb()
998 * - ly_get_log_clb()
Radek Krejcib50551c2016-04-19 09:15:38 +0200999 * - ly_errmsg()
1000 * - ly_errpath()
1001 * - ly_errapptag()
1002 * - #ly_errno
1003 * - #ly_vecode
Radek Krejci26715a42015-07-29 14:10:45 +02001004 */
1005
1006/**
Michal Vasko2d051a12017-04-21 09:28:57 +02001007 * @brief Number of internal modules, which are always in every context and cannot be removed nor disabled.
1008 */
1009#define LY_INTERNAL_MODULE_COUNT 5
1010
1011/**
Radek Krejci26715a42015-07-29 14:10:45 +02001012 * @defgroup context Context
Radek Krejci3045cf32015-05-28 10:58:52 +02001013 * @{
1014 *
Radek Krejci26715a42015-07-29 14:10:45 +02001015 * Structures and functions to manipulate with the libyang "containers". The \em context concept allows callers
1016 * to work in environments with different sets of YANG schemas. More detailed information can be found at
1017 * @ref howtocontext page.
Radek Krejci3045cf32015-05-28 10:58:52 +02001018 */
1019
1020/**
Radek Krejcida04f4a2015-05-21 12:54:09 +02001021 * @brief libyang context handler.
1022 */
1023struct ly_ctx;
1024
1025/**
1026 * @brief Create libyang context
1027 *
Radek Krejci26715a42015-07-29 14:10:45 +02001028 * Context is used to hold all information about schemas. Usually, the application is supposed
Radek Krejci91b833c2015-09-04 11:49:43 +02001029 * to work with a single context in which libyang is holding all schemas (and other internal
1030 * information) according to which the data trees will be processed and validated. So, the schema
1031 * trees are tightly connected with the specific context and they are held by the context internally
1032 * - caller does not need to keep pointers to the schemas returned by lys_parse(), context knows
1033 * about them. The data trees created with lyd_parse() are still connected with the specific context,
1034 * but they are not internally held by the context. The data tree just points and lean on some data
1035 * held by the context (schema tree, string dictionary, etc.). Therefore, in case of data trees, caller
1036 * is supposed to keep pointers returned by the lyd_parse() and manage the data tree on its own. This
1037 * also affects the number of instances of both tree types. While you can have only one instance of
1038 * specific schema connected with a single context, number of data tree instances is not connected.
Radek Krejcida04f4a2015-05-21 12:54:09 +02001039 *
Radek Krejci26715a42015-07-29 14:10:45 +02001040 * @param[in] search_dir Directory where libyang will search for the imported or included modules
1041 * and submodules. If no such directory is available, NULL is accepted.
Radek Krejcida04f4a2015-05-21 12:54:09 +02001042 *
Radek Krejci3045cf32015-05-28 10:58:52 +02001043 * @return Pointer to the created libyang context, NULL in case of error.
Radek Krejcida04f4a2015-05-21 12:54:09 +02001044 */
1045struct ly_ctx *ly_ctx_new(const char *search_dir);
1046
1047/**
Radek Krejci69333c92017-03-17 16:14:43 +01001048 * @brief Create libyang context according to the content of the given yang-library data.
1049 *
1050 * This function loads the yang-library data from the file at the given path. If you need
1051 * to pass the data as string, use ly_ctx_new_ylmem(). Both functions extend functionality of
1052 * ly_ctx_new() by loading modules specified in the ietf-yang-library form into the context
1053 * being created.
1054 *
1055 * Note, that the modules are loaded the same way as in case of ly_ctx_load_module(), so the schema
1056 * paths in the yang-library data are ignored and the modules are loaded from the context's search
1057 * locations. On the other hand, YANG features of the modules are set as specified in the yang-library
1058 * data.
1059 *
1060 * To get yang library data from a libyang context, use ly_ctx_info().
1061 *
1062 * @param[in] search_dir Directory where libyang will search for the imported or included modules
1063 * and submodules. If no such directory is available, NULL is accepted.
1064 * @param[in] path Path to the file containing yang-library data in the specified \p format.
1065 * @param[in] format Format of the data in the provided file.
1066 * @return Pointer to the created libyang context, NULL in case of error.
1067 */
1068struct ly_ctx *ly_ctx_new_ylpath(const char *search_dir, const char *path, LYD_FORMAT format);
1069
1070/**
1071 * @brief Create libyang context according to the content of the given yang-library data.
1072 *
1073 * This function loads the yang-library data from the given string. If you need to pass the data
1074 * as path to a file holding the data, use ly_ctx_new_ylpath(). Both functions extend functionality of
1075 * ly_ctx_new() by loading modules specified in the ietf-yang-library form into the context
1076 * being created.
1077 *
1078 * Note, that the modules are loaded the same way as in case of ly_ctx_load_module(), so the schema
1079 * paths in the yang-library data are ignored and the modules are loaded from the context's search
1080 * locations. On the other hand, YANG features of the modules are set as specified in the yang-library
1081 * data.
1082 *
1083 * To get yang library data from a libyang context, use ly_ctx_info().
1084 *
1085 * @param[in] search_dir Directory where libyang will search for the imported or included modules
1086 * and submodules. If no such directory is available, NULL is accepted.
1087 * @param[in] data String containing yang-library data in the specified \p format.
1088 * @param[in] format Format of the data in the provided file.
1089 * @return Pointer to the created libyang context, NULL in case of error.
1090 */
1091struct ly_ctx *ly_ctx_new_ylmem(const char *search_dir, const char *data, LYD_FORMAT format);
1092
1093/**
Radek Krejcida9f8392017-03-25 19:40:56 -05001094 * @brief Add the search path into libyang context
1095 *
1096 * To reset search paths set in the context, use ly_ctx_unset_searchdirs() and then
1097 * set search paths again.
Michal Vasko60ba9a62015-07-03 14:42:31 +02001098 *
1099 * @param[in] ctx Context to be modified.
Radek Krejcida9f8392017-03-25 19:40:56 -05001100 * @param[in] search_dir New search path to add to the current paths previously set in ctx.
Michal Vasko60ba9a62015-07-03 14:42:31 +02001101 */
1102void ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir);
1103
1104/**
Radek Krejcida9f8392017-03-25 19:40:56 -05001105 * @brief Clean all the search paths set in libyang context
1106 *
1107 * @param[in] ctx Context to be modified.
1108 */
1109void ly_ctx_unset_searchdirs(struct ly_ctx *ctx);
1110
1111/**
1112 * @brief Get value of the search path in libyang context
Radek Krejci5a797572015-10-21 15:45:45 +02001113 *
1114 * @param[in] ctx Context to query.
1115 * @return Current value of the search path.
1116 */
Michal Vasko1e62a092015-12-01 12:27:20 +01001117const char *ly_ctx_get_searchdir(const struct ly_ctx *ctx);
Radek Krejci5a797572015-10-21 15:45:45 +02001118
1119/**
Radek Krejci819dd4b2017-03-07 15:35:48 +01001120 * @brief Make context to set all the imported modules to be implemented. By default,
1121 * if the imported module is not used in leafref's path, augment or deviation, it is
1122 * imported and its data tree is not taken into account.
1123 *
1124 * Note, that function does not make the currently loaded modules, it just change the
1125 * schema parser behavior for the future parsing. This flag can be unset by ly_ctx_unset_allimplemented().
1126 *
1127 * @param[in] ctx Context to be modified.
1128 */
1129void ly_ctx_set_allimplemented(struct ly_ctx *ctx);
1130
1131/**
1132 * @brief Reverse function to ly_ctx_set_allimplemented().
1133 *
1134 * @param[in] ctx Context to be modified.
1135 */
1136void ly_ctx_unset_allimplemented(struct ly_ctx *ctx);
1137
1138/**
Radek Krejci7ab25152015-08-07 14:48:45 +02001139 * @brief Get data of an internal ietf-yang-library module.
1140 *
1141 * @param[in] ctx Context with the modules.
1142 * @return Root data node corresponding to the model, NULL on error.
1143 * Caller is responsible for freeing the returned data tree using lyd_free().
1144 */
1145struct lyd_node *ly_ctx_info(struct ly_ctx *ctx);
1146
1147/**
Radek Krejci0ec51da2016-12-14 16:42:03 +01001148 * @brief Iterate over all (enabled) modules in a context.
Michal Vaskod7957c02016-04-01 10:27:26 +02001149 *
1150 * @param[in] ctx Context with the modules.
1151 * @param[in,out] idx Index of the next module to be returned. Value of 0 starts from the beginning.
1152 * @return Next context module, NULL if the last was already returned.
1153 */
1154const struct lys_module *ly_ctx_get_module_iter(const struct ly_ctx *ctx, uint32_t *idx);
1155
1156/**
Radek Krejci0ec51da2016-12-14 16:42:03 +01001157 * @brief Iterate over the disabled modules in a context.
1158 *
1159 * @param[in] ctx Context with the modules.
1160 * @param[in,out] idx Index of the next module to be returned. Value of 0 starts from the beginning.
1161 * @return Next context module, NULL if the last was already returned.
1162 */
1163const struct lys_module *ly_ctx_get_disabled_module_iter(const struct ly_ctx *ctx, uint32_t *idx);
1164
1165/**
Radek Krejcifd4e6e32015-08-10 15:00:51 +02001166 * @brief Get pointer to the schema tree of the module of the specified name.
Radek Krejcida04f4a2015-05-21 12:54:09 +02001167 *
Radek Krejcida04f4a2015-05-21 12:54:09 +02001168 * @param[in] ctx Context to work in.
1169 * @param[in] name Name of the YANG module to get.
Radek Krejcif647e612015-07-30 11:36:07 +02001170 * @param[in] revision Optional revision date of the YANG module to get. If not specified,
1171 * the schema in the newest revision is returned if any.
1172 * @return Pointer to the data model structure, NULL if no schema following the name and
Radek Krejcifd4e6e32015-08-10 15:00:51 +02001173 * revision requirements is present in the context.
Radek Krejcida04f4a2015-05-21 12:54:09 +02001174 */
Michal Vasko1e62a092015-12-01 12:27:20 +01001175const struct lys_module *ly_ctx_get_module(const struct ly_ctx *ctx, const char *name, const char *revision);
Radek Krejcida04f4a2015-05-21 12:54:09 +02001176
1177/**
Radek Krejci21601a32016-03-07 11:39:27 +01001178 * @brief Get pointer to the older schema tree to the specified one in the provided context.
1179 *
1180 * The module is not necessarily from the provided \p ctx. If there are multiple schemas older than the
1181 * provided one, the newest of them is returned.
1182 *
1183 * The function can be used in combination with ly_ctx_get_module() to get all revisions of a module in a context:
1184 * \code{.c}
1185 * for (mod = ly_ctx_get_module(ctx, name, NULL); mod; mod = ly_ctx_get_module_older(ctx, mod)) {
1186 * ...
1187 * }
1188 * \endcode
1189 *
1190 * @param[in] ctx Context to work in.
1191 * @param[in] module YANG module to compare with
1192 * @return Pointer to the data model structure, NULL if no older schema is present in the context.
1193 */
1194const struct lys_module *ly_ctx_get_module_older(const struct ly_ctx *ctx, const struct lys_module *module);
1195
1196/**
Michal Vasko99b0aad2015-12-01 12:28:51 +01001197 * @brief Try to find the model in the searchpath of \p ctx and load it into it. If custom missing
1198 * module callback is set, it is used instead.
Michal Vasko82465962015-11-10 11:03:11 +01001199 *
Radek Krejci31fb8be2016-06-23 15:26:26 +02001200 * If there is a possibility that the requested module is already in the context, you should call
1201 * the ly_ctx_get_module() first to avoid a lot of work performed by ly_ctx_load_module().
1202 *
Michal Vasko82465962015-11-10 11:03:11 +01001203 * @param[in] ctx Context to add to.
Michal Vasko82465962015-11-10 11:03:11 +01001204 * @param[in] name Name of the module to load.
1205 * @param[in] revision Optional revision date of the module. If not specified, it is
1206 * assumed that there is only one model revision in the searchpath (the first matching file
1207 * is parsed).
1208 * @return Pointer to the data model structure, NULL if not found or some error occured.
1209 */
Michal Vasko99b0aad2015-12-01 12:28:51 +01001210const struct lys_module *ly_ctx_load_module(struct ly_ctx *ctx, const char *name, const char *revision);
1211
1212/**
1213 * @brief Callback for retrieving missing included or imported models in a custom way.
1214 *
Michal Vasko84475152016-07-25 16:16:25 +02001215 * @param[in] mod_name Missing module name.
1216 * @param[in] mod_rev Optional missing module revision.
1217 * @param[in] submod_name Optional missing submodule name.
1218 * @param[in] submod_rev Optional missing submodule revision.
Michal Vasko99b0aad2015-12-01 12:28:51 +01001219 * @param[in] user_data User-supplied callback data.
1220 * @param[out] format Format of the returned module data.
Michal Vasko880dceb2016-03-03 15:44:56 +01001221 * @param[out] free_module_data Callback for freeing the returned module data. If not set, the data will be left untouched.
Radek Krejci31fb8be2016-06-23 15:26:26 +02001222 * @return Requested module data or NULL if the callback is not able to provide the requested schema content for any reason.
Michal Vasko99b0aad2015-12-01 12:28:51 +01001223 */
Michal Vaskof53187d2017-01-13 13:23:14 +01001224typedef char *(*ly_module_imp_clb)(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev,
1225 void *user_data, LYS_INFORMAT *format, void (**free_module_data)(void *model_data));
Michal Vasko99b0aad2015-12-01 12:28:51 +01001226
1227/**
Michal Vasko98b5f952016-10-26 12:14:40 +02001228 * @brief Set missing include or import module callback. It is meant to be used when the models
1229 * are not locally available (such as when downloading modules from a NETCONF server), it should
1230 * not be required in other cases.
Michal Vasko99b0aad2015-12-01 12:28:51 +01001231 *
1232 * @param[in] ctx Context that will use this callback.
Michal Vaskof53187d2017-01-13 13:23:14 +01001233 * @param[in] clb Callback responsible for returning the missing model.
Michal Vasko99b0aad2015-12-01 12:28:51 +01001234 * @param[in] user_data Arbitrary data that will always be passed to the callback \p clb.
1235 */
Michal Vaskof53187d2017-01-13 13:23:14 +01001236void ly_ctx_set_module_imp_clb(struct ly_ctx *ctx, ly_module_imp_clb clb, void *user_data);
Michal Vasko99b0aad2015-12-01 12:28:51 +01001237
1238/**
Michal Vaskof53187d2017-01-13 13:23:14 +01001239 * @brief Get the custom callback for missing import/include module retrieval.
1240 *
1241 * @param[in] ctx Context to read from.
1242 * @param[in] user_data Optional pointer for getting the user-supplied callback data.
1243 * @return Callback or NULL if not set.
1244 */
1245ly_module_imp_clb ly_ctx_get_module_imp_clb(const struct ly_ctx *ctx, void **user_data);
1246
1247/**
1248 * @brief Callback for retrieving missing modules in the context, for which some data was found.
1249 *
1250 * Either \p name or \p ns is ALWAYS set, but both can also be set.
1251 *
1252 * @param[in,out] ctx Context with the missing module.
1253 * @param[in] name Missing module name.
1254 * @param[in] ns Missing module namespace.
1255 * @param[in] options Bitmask of LY_MODCLB_* values or 0.
1256 * @param[in] user_data User-supplied callback data.
1257 * @return Newly added or modified module, NULL on failure.
1258 */
1259typedef const struct lys_module *(*ly_module_data_clb)(struct ly_ctx *ctx, const char *name, const char *ns,
1260 int options, void *user_data);
1261
1262/* Module is in the context, but is not implemented, so to continue with the data operation, it must be implemented. */
1263#define LY_MODCLB_NOT_IMPLEMENTED 0x01
1264
1265/**
1266 * @brief Set the missing data module callback. It will be called when some data is parsed or searched for and their module
1267 * is not found in the context or is not implemented.
1268 *
1269 * @param[in] ctx Context that will use this callback.
1270 * @param[in] clb Callback responsible for returning the missing model.
1271 * @param[in] user_data Arbitrary data that will always be passed to the callback \p clb.
1272 */
1273void ly_ctx_set_module_data_clb(struct ly_ctx *ctx, ly_module_data_clb clb, void *user_data);
1274
1275/**
1276 * @brief Get the missing data module calback.
Michal Vasko99b0aad2015-12-01 12:28:51 +01001277 *
1278 * @param[in] ctx Context to read from.
1279 * @param[in] user_data Optional pointer for getting the user-supplied callbck data.
Michal Vaskof53187d2017-01-13 13:23:14 +01001280 * @return Callback or NULL if not set.
Michal Vasko99b0aad2015-12-01 12:28:51 +01001281 */
Michal Vaskof53187d2017-01-13 13:23:14 +01001282ly_module_data_clb ly_ctx_get_module_data_clb(const struct ly_ctx *ctx, void **user_data);
Michal Vasko82465962015-11-10 11:03:11 +01001283
1284/**
Radek Krejcifd4e6e32015-08-10 15:00:51 +02001285 * @brief Get pointer to the schema tree of the module of the specified namespace
1286 *
1287 * @param[in] ctx Context to work in.
1288 * @param[in] ns Namespace of the YANG module to get.
1289 * @param[in] revision Optional revision date of the YANG module to get. If not specified,
1290 * the schema in the newest revision is returned if any.
1291 * @return Pointer to the data model structure, NULL if no schema following the namespace and
1292 * revision requirements is present in the context.
1293 */
Michal Vasko1e62a092015-12-01 12:27:20 +01001294const struct lys_module *ly_ctx_get_module_by_ns(const struct ly_ctx *ctx, const char *ns, const char *revision);
Radek Krejcifd4e6e32015-08-10 15:00:51 +02001295
1296/**
Radek Krejci62f0da72016-03-07 11:35:43 +01001297 * @brief Get submodule of a main module.
1298 *
1299 * If you already have the pointer to the submodule's main module, use ly_ctx_get_submodule2() instead.
Michal Vasko7bf06882015-07-03 15:33:56 +02001300 *
Radek Krejcia7533f22016-03-07 07:37:45 +01001301 * @param[in] ctx Context to work in.
Michal Vaskof6d94c62016-04-05 11:21:54 +02001302 * @param[in] module Name of the main (belongs-to) module. If NULL, all module submodules are searched.
1303 * @param[in] revision Optional revision date of \p module. If NULL, all revisions of \p module
1304 * are searched. If set, \p module must also be set.
Radek Krejcia7533f22016-03-07 07:37:45 +01001305 * @param[in] submodule Name of the submodule to get.
Michal Vaskof6d94c62016-04-05 11:21:54 +02001306 * @param[in] sub_revision Optional revision date of \p submodule. If NULL, the newest revision of \p submodule
1307 * is returned.
Michal Vasko7bf06882015-07-03 15:33:56 +02001308 * @return Pointer to the data model structure.
1309 */
Radek Krejcia7533f22016-03-07 07:37:45 +01001310const struct lys_submodule *ly_ctx_get_submodule(const struct ly_ctx *ctx, const char *module, const char *revision,
Michal Vaskof6d94c62016-04-05 11:21:54 +02001311 const char *submodule, const char *sub_revision);
Michal Vasko7bf06882015-07-03 15:33:56 +02001312
1313/**
Radek Krejci62f0da72016-03-07 11:35:43 +01001314 * @brief Get submodule of a main module.
1315 *
1316 * If you have only the name (and optionally revision) of the submodule's main module, use ly_ctx_get_submodule()
1317 * instead.
1318 *
1319 * @param[in] main_module Main module (belongs to) of the searched submodule.
1320 * @param[in] submodule Name of the submodule to get.
1321 * @return Pointer to the data model structure.
1322 */
1323const struct lys_submodule *ly_ctx_get_submodule2(const struct lys_module *main_module, const char *submodule);
1324
1325/**
Michal Vasko3547c532016-03-14 09:40:50 +01001326 * @brief Get schema node according to the given schema node identifier in JSON format.
Michal Vasko3edeaf72016-02-11 13:17:43 +01001327 *
Michal Vasko3547c532016-03-14 09:40:50 +01001328 * If the \p nodeid is absolute, the first node identifier must be prefixed with
1329 * the module name. Then every other identifier either has an explicit module name or
1330 * the module name of the previous node is assumed. Examples:
Michal Vasko3edeaf72016-02-11 13:17:43 +01001331 *
1332 * /ietf-netconf-monitoring:get-schema/input/identifier
1333 * /ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address/ip
1334 *
Michal Vasko3547c532016-03-14 09:40:50 +01001335 * If the \p nodeid is relative, \p start is mandatory and is the starting point
1336 * for the resolution. The first node identifier does not need a module name.
1337 *
Michal Vasko7b54f7e2016-05-03 15:07:31 +02001338 * Predicates on lists are accepted (ignored) in the form of "<key>(=<value>)"
1339 * and on leaves/leaf-lists ".(=<value>)".
1340 *
Michal Vasko3edeaf72016-02-11 13:17:43 +01001341 * @param[in] ctx Context to work in.
Michal Vasko3547c532016-03-14 09:40:50 +01001342 * @param[in] start Starting node for a relative schema node identifier, in which
1343 * case it is mandatory.
1344 * @param[in] nodeid JSON schema node identifier.
Michal Vasko3edeaf72016-02-11 13:17:43 +01001345 * @return Resolved schema node or NULL.
1346 */
Michal Vasko3547c532016-03-14 09:40:50 +01001347const struct lys_node *ly_ctx_get_node(struct ly_ctx *ctx, const struct lys_node *start, const char *nodeid);
Michal Vasko3edeaf72016-02-11 13:17:43 +01001348
1349/**
Radek Krejci0ec51da2016-12-14 16:42:03 +01001350 * @brief Remove the specified module from its context.
Radek Krejci8c107fe2016-10-17 16:00:18 +02001351 *
Radek Krejci0ec51da2016-12-14 16:42:03 +01001352 * Beside the selected module, also all other modules depending on all the modules being removed
1353 * will be removed as well.
Radek Krejci8c107fe2016-10-17 16:00:18 +02001354 *
1355 * libyang internal modules (those present when the context is created) cannot be removed.
1356 *
Radek Krejci0ec51da2016-12-14 16:42:03 +01001357 * @param[in] module Module to be removed.
Radek Krejci8c107fe2016-10-17 16:00:18 +02001358 * @param[in] private_destructor Optional destructor function for private objects assigned
1359 * to the nodes via lys_set_private(). If NULL, the private objects are not freed by libyang.
Radek Krejci0ec51da2016-12-14 16:42:03 +01001360 * @return EXIT_SUCCESS or EXIT_FAILURE (in case of invalid parameter).
Radek Krejci8c107fe2016-10-17 16:00:18 +02001361 */
Radek Krejci0ec51da2016-12-14 16:42:03 +01001362int ly_ctx_remove_module(const struct lys_module *module,
Radek Krejci8c107fe2016-10-17 16:00:18 +02001363 void (*private_destructor)(const struct lys_node *node, void *priv));
1364
1365/**
1366 * @brief Remove all the modules from the context except the internal modules. Also the addition data in
1367 * dictionary are kept.
1368 *
1369 * @param[in] ctx Context to work in.
1370 * @param[in] private_destructor Optional destructor function for private objects assigned
1371 * to the nodes via lys_set_private(). If NULL, the private objects are not freed by libyang.
1372 */
1373void ly_ctx_clean(struct ly_ctx *ctx, void (*private_destructor)(const struct lys_node *node, void *priv));
1374
1375/**
Radek Krejci3045cf32015-05-28 10:58:52 +02001376 * @brief Free all internal structures of the specified context.
1377 *
1378 * The function should be used before terminating the application to destroy
1379 * and free all structures internally used by libyang. If the caller uses
1380 * multiple contexts, the function should be called for each used context.
1381 *
1382 * All instance data are supposed to be freed before destroying the context.
1383 * Data models are destroyed automatically as part of ly_ctx_destroy() call.
1384 *
1385 * @param[in] ctx libyang context to destroy
Radek Krejcifa0b5e02016-02-04 13:57:03 +01001386 * @param[in] private_destructor Optional destructor function for private objects assigned
1387 * to the nodes via lys_set_private(). If NULL, the private objects are not freed by libyang.
Radek Krejci5138e9f2017-04-12 13:10:46 +02001388 * Remember the differences between the structures derived from ::lys_node and always check
1389 * ::lys_node#nodetype.
Radek Krejcida04f4a2015-05-21 12:54:09 +02001390 */
Radek Krejcifa0b5e02016-02-04 13:57:03 +01001391void ly_ctx_destroy(struct ly_ctx *ctx, void (*private_destructor)(const struct lys_node *node, void *priv));
Radek Krejcida04f4a2015-05-21 12:54:09 +02001392
Radek Krejci26715a42015-07-29 14:10:45 +02001393/**@} context */
1394
1395/**
Radek Krejcidef50022016-02-01 16:38:32 +01001396 * @defgroup nodeset Tree nodes set
Radek Krejcidc154432016-01-21 11:10:59 +01001397 * @ingroup datatree
1398 * @ingroup schematree
1399 * @{
1400 *
Radek Krejcidef50022016-02-01 16:38:32 +01001401 * Structure and functions to hold and manipulate with sets of nodes from schema or data trees.
1402 */
1403
1404/**
Radek Krejci8f08df12016-03-21 11:11:30 +01001405 * @brief set array of ::ly_set
1406 * It is kept in union to keep ::ly_set generic for data as well as schema trees
1407 */
1408union ly_set_set {
1409 struct lys_node **s; /**< array of pointers to a ::lys_node objects */
1410 struct lyd_node **d; /**< array of pointers to a ::lyd_node objects */
1411 void **g; /**< dummy array for generic work */
1412};
1413
1414/**
Radek Krejcidc154432016-01-21 11:10:59 +01001415 * @brief Structure to hold a set of (not necessary somehow connected) ::lyd_node or ::lys_node objects.
1416 * Caller is supposed to not mix the type of objects added to the set and according to its knowledge about
1417 * the set content, it is supposed to access the set via the sset, dset or set members of the structure.
1418 *
Radek Krejci09891a22016-06-10 10:59:22 +02001419 * Until ly_set_rm() or ly_set_rm_index() is used, the set keeps the order of the inserted items as they
1420 * were added into the set, so the first added item is on array index 0.
1421 *
Radek Krejcidef50022016-02-01 16:38:32 +01001422 * To free the structure, use ly_set_free() function, to manipulate with the structure, use other
1423 * ly_set_* functions.
Radek Krejcidc154432016-01-21 11:10:59 +01001424 */
1425struct ly_set {
1426 unsigned int size; /**< allocated size of the set array */
1427 unsigned int number; /**< number of elements in (used size of) the set array */
Radek Krejci8f08df12016-03-21 11:11:30 +01001428 union ly_set_set set; /**< set array - union to keep ::ly_set generic for data as well as schema trees */
Radek Krejcidc154432016-01-21 11:10:59 +01001429};
1430
1431/**
Radek Krejci09891a22016-06-10 10:59:22 +02001432 * @brief Option for ly_set_add() to allow duplicities in the ly_set structure so the
1433 * set is not used as a set, but as a list of (container for) items.
1434 */
1435#define LY_SET_OPT_USEASLIST 0x01
1436
1437/**
Radek Krejcidef50022016-02-01 16:38:32 +01001438 * @brief Create and initiate new ::ly_set structure.
Radek Krejcidc154432016-01-21 11:10:59 +01001439 *
Radek Krejcidef50022016-02-01 16:38:32 +01001440 * @return Created ::ly_set structure or NULL in case of error.
Radek Krejcidc154432016-01-21 11:10:59 +01001441 */
1442struct ly_set *ly_set_new(void);
1443
1444/**
Radek Krejcie8c1b572016-07-26 15:09:52 +02001445 * @brief Duplicate the existing set.
1446 *
1447 * @param[in] set Original set to duplicate
1448 * @return Duplication of the original set.
1449 */
1450struct ly_set *ly_set_dup(const struct ly_set *set);
1451
1452/**
Radek Krejcidc154432016-01-21 11:10:59 +01001453 * @brief Add a ::lyd_node or ::lys_node object into the set
1454 *
Radek Krejci29cb50d2016-05-09 16:31:13 +02001455 * Since it is a set, the function checks for duplicity and if the
1456 * node is already in the set, the index of the previously added
1457 * node is returned.
1458 *
Radek Krejcidc154432016-01-21 11:10:59 +01001459 * @param[in] set Set where the \p node will be added.
1460 * @param[in] node The ::lyd_node or ::lys_node object to be added into the \p set;
Radek Krejci09891a22016-06-10 10:59:22 +02001461 * @param[in] options Options to change behavior of the function. Accepted options are:
1462 * - #LY_SET_OPT_USEASLIST - do not check for duplicities
Radek Krejci29cb50d2016-05-09 16:31:13 +02001463 * @return -1 on failure, index of the \p node in the set on success
Radek Krejcidc154432016-01-21 11:10:59 +01001464 */
Radek Krejci09891a22016-06-10 10:59:22 +02001465int ly_set_add(struct ly_set *set, void *node, int options);
Radek Krejcidc154432016-01-21 11:10:59 +01001466
1467/**
Radek Krejci99e6d9a2016-10-20 13:01:43 +02001468 * @brief Get know if the set contains the specified object.
1469 * @param[in] set Set to explore.
1470 * @param[in] node Object to be found in the set.
1471 * @return Index of the object in the set or -1 if the object is not present in the set.
Radek Krejci3e112292016-10-20 13:10:30 +02001472 */
Radek Krejci99e6d9a2016-10-20 13:01:43 +02001473int ly_set_contains(const struct ly_set *set, void *node);
1474
1475/**
Radek Krejci29ed4082016-05-09 14:25:56 +02001476 * @brief Remove all objects from the set, but keep the set container for further use.
1477 *
1478 * @param[in] set Set to clean.
1479 * @return 0 on success
1480 */
1481int ly_set_clean(struct ly_set *set);
1482
1483/**
Radek Krejcidc154432016-01-21 11:10:59 +01001484 * @brief Remove a ::lyd_node or ::lys_node object from the set.
1485 *
1486 * Note that after removing a node from a set, indexes of other nodes in the set can change
1487 * (the last object is placed instead of the removed object).
1488 *
1489 * @param[in] set Set from which the \p node will be removed.
1490 * @param[in] node The ::lyd_node or ::lys_node object to be removed from the \p set;
1491 * @return 0 on success
1492 */
1493int ly_set_rm(struct ly_set *set, void *node);
1494
1495/**
1496 * @brief Remove a ::lyd_node or ::lys_node object from the set index.
1497 *
1498 * Note that after removing a node from a set, indexes of other nodes in the set can change
1499 * (the last object is placed instead of the removed object).
1500 *
1501 * @param[in] set Set from which a node will be removed.
1502 * @param[in] index Index of the ::lyd_node or ::lys_node object in the \p set to be removed from the \p set;
1503 * @return 0 on success
1504 */
1505int ly_set_rm_index(struct ly_set *set, unsigned int index);
1506
1507/**
Radek Krejcidef50022016-02-01 16:38:32 +01001508 * @brief Free the ::ly_set data. Frees only the set structure content, not the referred data.
Radek Krejcidc154432016-01-21 11:10:59 +01001509 *
1510 * @param[in] set The set to be freed.
1511 */
1512void ly_set_free(struct ly_set *set);
1513
Radek Krejcidef50022016-02-01 16:38:32 +01001514/**@} nodeset */
Radek Krejci6140e4e2015-10-09 15:50:55 +02001515
1516/**
Radek Krejci5044be32016-01-18 17:05:51 +01001517 * @defgroup printerflags Printer flags
Radek Krejcidef50022016-02-01 16:38:32 +01001518 * @ingroup datatree
Radek Krejci5044be32016-01-18 17:05:51 +01001519 *
1520 * Validity flags for data nodes.
1521 *
1522 * @{
1523 */
Michal Vasko6216f272016-10-18 11:49:47 +02001524#define LYP_WITHSIBLINGS 0x01 /**< Flag for printing also the (following) sibling nodes of the data node. */
1525#define LYP_FORMAT 0x02 /**< Flag for formatted output. */
1526#define LYP_KEEPEMPTYCONT 0x04 /**< Preserve empty non-presence containers */
1527#define LYP_WD_MASK 0xF0 /**< Mask for with-defaults modes */
1528#define LYP_WD_EXPLICIT 0x00 /**< Explicit mode - print only data explicitly being present in the data tree.
1529 Note that this is the default value when no WD option is specified. */
1530#define LYP_WD_TRIM 0x10 /**< Do not print the nodes with the value equal to their default value */
1531#define LYP_WD_ALL 0x20 /**< Include implicit default nodes */
1532#define LYP_WD_ALL_TAG 0x40 /**< Same as #LYP_WD_ALL but also adds attribute 'default' with value 'true' to
1533 all nodes that has its default value. The 'default' attribute has namespace:
1534 urn:ietf:params:xml:ns:netconf:default:1.0 and thus the attributes are
1535 printed only when the ietf-netconf-with-defaults module is present in libyang
Michal Vaskoe77dc992017-01-18 12:09:42 +01001536 context (but in that case this namespace is always printed). */
Michal Vasko6216f272016-10-18 11:49:47 +02001537#define LYP_WD_IMPL_TAG 0x80 /**< Same as LYP_WD_ALL_TAG but the attributes are added only to the nodes that
1538 are not explicitly present in the original data tree despite their
1539 value is equal to their default value. There is the same limitation regarding
1540 the presence of ietf-netconf-with-defaults module in libyang context. */
Michal Vaskoafa7a642016-10-18 15:11:38 +02001541#define LYP_NETCONF 0x100 /**< Print the data tree for use in NETCONF meaning:
Michal Vasko6216f272016-10-18 11:49:47 +02001542 - for RPC output - skip the top-level RPC node,
1543 - for action output - skip all the parents of and the action node itself,
1544 - for action input - enclose the data in an action element in the base YANG namespace,
1545 - for all other data - print the whole data tree normally. */
Radek Krejci5044be32016-01-18 17:05:51 +01001546
1547/**
1548 * @}
1549 */
1550
1551/**
Radek Krejci3045cf32015-05-28 10:58:52 +02001552 * @defgroup logger Logger
1553 * @{
1554 *
1555 * Publicly visible functions and values of the libyang logger. For more
1556 * information, see \ref howtologger.
1557 */
1558
1559/**
1560 * @typedef LY_LOG_LEVEL
1561 * @brief Verbosity levels of the libyang logger.
1562 */
1563typedef enum {
Michal Vasko8f7e8d92016-07-01 11:33:58 +02001564 LY_LLSILENT = -1, /**< Print no messages. */
1565 LY_LLERR = 0, /**< Print only error messages, default value. */
1566 LY_LLWRN, /**< Print error and warning messages. */
1567 LY_LLVRB, /**< Besides errors and warnings, print some other verbose messages. */
Michal Vasko3e3228d2017-02-24 14:55:32 +01001568 LY_LLDBG /**< Print all messages including some development debug messages (be careful,
1569 without subsequently calling ly_verb_dbg() no debug messages will be printed!). */
Radek Krejci3045cf32015-05-28 10:58:52 +02001570} LY_LOG_LEVEL;
1571
1572/**
1573 * @brief Set logger verbosity level.
1574 * @param[in] level Verbosity level.
Radek Krejci5f9127b2017-06-12 16:42:00 +02001575 * @return Previous verbosity level.
Radek Krejci3045cf32015-05-28 10:58:52 +02001576 */
Radek Krejci5f9127b2017-06-12 16:42:00 +02001577LY_LOG_LEVEL ly_verb(LY_LOG_LEVEL level);
Radek Krejci3045cf32015-05-28 10:58:52 +02001578
Michal Vasko3e3228d2017-02-24 14:55:32 +01001579#ifndef NDEBUG
1580
1581/**
1582 * @typedef LY_LOG_DBG_GROUP
1583 * @brief Selected displayed debug message groups.
1584 */
1585typedef enum {
1586 LY_LDGDICT = 0x01, /**< Dictionary additions and deletions. */
1587 LY_LDGYANG = 0x02, /**< YANG parser messages. */
1588 LY_LDGYIN = 0x04, /**< YIN parser messages. */
1589 LY_LDGXPATH = 0x08, /**< XPath parsing end evaluation. */
1590 LY_LDGDIFF = 0x10 /**< Diff processing and creation. */
1591} LY_LOG_DBG_GROUP;
1592
1593/**
1594 * @brief Enable specific debugging messages (independent of log level).
1595 * @param[in] dbg_groups Bitfield of #LY_LOG_DBG_GROUP - enabled debug message groups.
1596 */
1597void ly_verb_dbg(int dbg_groups);
1598
1599#endif
1600
Radek Krejci3045cf32015-05-28 10:58:52 +02001601/**
Michal Vaskof1d62cf2015-12-07 13:17:11 +01001602 * @brief Set logger callback.
Michal Vasko13661142016-04-11 10:53:53 +02001603 *
1604 * !IMPORTANT! If an error has a specific error-app-tag defined in the model, it will NOT be set
1605 * at the time of calling this callback. It will be set right after, so to retrieve it
1606 * it must be checked afterwards with ly_errapptag().
1607 *
Michal Vaskof1d62cf2015-12-07 13:17:11 +01001608 * @param[in] clb Logging callback.
Radek Krejciadb57612016-02-16 13:34:34 +01001609 * @param[in] path flag to resolve and provide path as the third parameter of the callback function. In case of
1610 * validation and some other errors, it can be useful to get the path to the problematic element. Note,
1611 * that according to the tree type and the specific situation, the path can slightly differs (keys
1612 * presence) or it can be NULL, so consider it as an optional parameter. If the flag is 0, libyang will
1613 * not bother with resolving the path.
Michal Vaskof1d62cf2015-12-07 13:17:11 +01001614 */
Radek Krejciadb57612016-02-16 13:34:34 +01001615void ly_set_log_clb(void (*clb)(LY_LOG_LEVEL level, const char *msg, const char *path), int path);
Michal Vaskof1d62cf2015-12-07 13:17:11 +01001616
1617/**
1618 * @brief Get logger callback.
1619 * @return Logger callback (can be NULL).
1620 */
Radek Krejciadb57612016-02-16 13:34:34 +01001621void (*ly_get_log_clb(void))(LY_LOG_LEVEL, const char *, const char *);
Michal Vaskof1d62cf2015-12-07 13:17:11 +01001622
1623/**
Radek Krejci3045cf32015-05-28 10:58:52 +02001624 * @typedef LY_ERR
Radek Krejci26715a42015-07-29 14:10:45 +02001625 * @brief libyang's error codes available via ly_errno extern variable.
Radek Krejci9b4ca392015-04-10 08:31:27 +02001626 * @ingroup logger
1627 */
1628typedef enum {
Radek Krejciae6817a2015-08-10 14:02:06 +02001629 LY_SUCCESS, /**< no error, not set by functions, included just to complete #LY_ERR enumeration */
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001630 LY_EMEM, /**< Memory allocation failure */
1631 LY_ESYS, /**< System call failure */
1632 LY_EINVAL, /**< Invalid value */
1633 LY_EINT, /**< Internal error */
Radek Krejci2c121b32017-02-24 10:03:16 +01001634 LY_EVALID, /**< Validation failure */
1635 LY_EEXT /**< Extension error reported by an extension plugin */
Radek Krejci3045cf32015-05-28 10:58:52 +02001636} LY_ERR;
Radek Krejci7d9f46a2016-01-29 13:53:18 +01001637
Radek Krejci26715a42015-07-29 14:10:45 +02001638/**
Michal Vaskof5035ce2016-03-11 10:21:31 +01001639 * @typedef LY_VECODE
1640 * @brief libyang's codes of validation error. Whenever ly_errno is set to LY_EVALID, the ly_vecode is also set
1641 * to the appropriate LY_VECODE value.
Radek Krejcia37b39c2016-03-09 16:38:18 +01001642 * @ingroup logger
1643 */
1644typedef enum {
Michal Vaskof5035ce2016-03-11 10:21:31 +01001645 LYVE_SUCCESS = 0, /**< no error */
Radek Krejcia37b39c2016-03-09 16:38:18 +01001646
Michal Vaskof5035ce2016-03-11 10:21:31 +01001647 LYVE_XML_MISS, /**< missing XML object */
1648 LYVE_XML_INVAL, /**< invalid XML object */
1649 LYVE_XML_INCHAR, /**< invalid XML character */
Radek Krejcia37b39c2016-03-09 16:38:18 +01001650
Michal Vaskof5035ce2016-03-11 10:21:31 +01001651 LYVE_EOF, /**< unexpected end of input data */
1652 LYVE_INSTMT, /**< invalid statement (schema) */
1653 /* */
Michal Vaskoca7cbc42016-07-01 11:36:53 +02001654 LYVE_INPAR, /**< invalid (in)direct parent (schema) */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001655 LYVE_INID, /**< invalid identifier (schema) */
1656 LYVE_INDATE, /**< invalid date format */
1657 LYVE_INARG, /**< invalid value of a statement argument (schema) */
1658 LYVE_MISSSTMT, /**< missing required statement (schema) */
1659 /* */
1660 LYVE_MISSARG, /**< missing required statement argument (schema) */
1661 LYVE_TOOMANY, /**< too many instances of some object */
1662 LYVE_DUPID, /**< duplicated identifier (schema) */
1663 LYVE_DUPLEAFLIST, /**< multiple instances of leaf-list */
1664 LYVE_DUPLIST, /**< multiple instances of list */
Michal Vaskoa540df22016-04-11 16:14:35 +02001665 LYVE_NOUNIQ, /**< unique leaves match on 2 list instances (data) */
Radek Krejcie663e012016-08-01 17:12:34 +02001666 LYVE_ENUM_INVAL, /**< invalid enum value (schema) */
1667 LYVE_ENUM_INNAME, /**< invalid enum name (schema) */
1668 /* */
1669 /* */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001670 LYVE_ENUM_WS, /**< enum name with leading/trailing whitespaces (schema) */
Radek Krejcie663e012016-08-01 17:12:34 +02001671 LYVE_BITS_INVAL, /**< invalid bits value (schema) */
1672 LYVE_BITS_INNAME, /**< invalid bits name (schema) */
1673 /* */
1674 /* */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001675 LYVE_INMOD, /**< invalid module name */
1676 /* */
1677 LYVE_KEY_NLEAF, /**< list key is not a leaf (schema) */
1678 LYVE_KEY_TYPE, /**< invalid list key type (schema) */
1679 LYVE_KEY_CONFIG, /**< key config value differs from the list config value */
1680 LYVE_KEY_MISS, /**< list key not found (schema) */
1681 LYVE_KEY_DUP, /**< duplicated key identifier (schema) */
1682 LYVE_INREGEX, /**< invalid regular expression (schema) */
1683 LYVE_INRESOLV, /**< no resolvents found (schema) */
1684 LYVE_INSTATUS, /**< invalid derivation because of status (schema) */
Radek Krejcid8fb03c2016-06-13 15:52:22 +02001685 LYVE_CIRC_LEAFREFS,/**< circular chain of leafrefs detected (schema) */
Radek Krejcie8c1b572016-07-26 15:09:52 +02001686 LYVE_CIRC_FEATURES,/**< circular chain of features detected (schema) */
Radek Krejci151b8cc2016-06-22 10:14:21 +02001687 LYVE_CIRC_IMPORTS, /**< circular chain of imports detected (schema) */
1688 LYVE_CIRC_INCLUDES,/**< circular chain of includes detected (schema) */
Michal Vasko88de3e42016-06-29 11:05:32 +02001689 LYVE_INVER, /**< non-matching YANG versions of module and its submodules (schema) */
Radek Krejci0fd6a992016-11-08 19:42:20 +01001690 LYVE_SUBMODULE, /**< submodule given instead of a module */
Radek Krejcia37b39c2016-03-09 16:38:18 +01001691
Michal Vaskof5035ce2016-03-11 10:21:31 +01001692 LYVE_OBSDATA, /**< obsolete data instantiation (data) */
1693 /* */
1694 LYVE_NORESOLV, /**< no resolvents found for an expression (data) */
1695 LYVE_INELEM, /**< invalid element (data) */
1696 /* */
1697 LYVE_MISSELEM, /**< missing required element (data) */
1698 LYVE_INVAL, /**< invalid value of an element (data) */
Michal Vasko4bff75f2017-03-02 10:48:44 +01001699 LYVE_INMETA, /**< invalid metadata (attribute) value (data) */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001700 LYVE_INATTR, /**< invalid attribute in an element (data) */
1701 LYVE_MISSATTR, /**< missing attribute in an element (data) */
Michal Vasko6ac68282016-04-11 10:56:47 +02001702 LYVE_NOCONSTR, /**< value out of range/length/pattern (data) */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001703 LYVE_INCHAR, /**< unexpected characters (data) */
1704 LYVE_INPRED, /**< predicate resolution fail (data) */
1705 LYVE_MCASEDATA, /**< data for more cases of a choice (data) */
Michal Vasko6ac68282016-04-11 10:56:47 +02001706 LYVE_NOMUST, /**< unsatisfied must condition (data) */
1707 LYVE_NOWHEN, /**< unsatisfied when condition (data) */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001708 LYVE_INORDER, /**< invalid order of elements (data) */
Radek Krejci03b71f72016-03-16 11:10:09 +01001709 LYVE_INWHEN, /**< irresolvable when condition (data) */
Michal Vasko6ac68282016-04-11 10:56:47 +02001710 LYVE_NOMIN, /**< min-elements constraint not honored (data) */
1711 LYVE_NOMAX, /**< max-elements constraint not honored (data) */
1712 LYVE_NOREQINS, /**< required instance does not exits (data) */
1713 LYVE_NOLEAFREF, /**< leaf pointed to by leafref does not exist (data) */
1714 LYVE_NOMANDCHOICE, /**< no mandatory choice case branch exists (data) */
Radek Krejcia37b39c2016-03-09 16:38:18 +01001715
Michal Vasko5b3492c2016-07-20 09:37:40 +02001716 LYVE_XPATH_INSNODE,/**< schema node not found */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001717 LYVE_XPATH_INTOK, /**< unexpected XPath token */
1718 LYVE_XPATH_EOF, /**< unexpected end of an XPath expression */
1719 LYVE_XPATH_INOP, /**< invalid XPath operation operands */
1720 /* */
1721 LYVE_XPATH_INCTX, /**< invalid XPath context type */
Michal Vasko541dff42016-10-26 11:29:25 +02001722 LYVE_XPATH_INMOD, /**< invalid module name */
Michal Vasko93909772016-10-26 10:32:10 +02001723 LYVE_XPATH_INFUNC, /**< invalid XPath function name */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001724 LYVE_XPATH_INARGCOUNT, /**< invalid number of arguments for an XPath function */
Michal Vasko6fae1362016-03-11 15:10:00 +01001725 LYVE_XPATH_INARGTYPE, /**< invalid type of arguments for an XPath function */
Michal Vasko283bf382017-05-03 12:29:40 +02001726 LYVE_XPATH_DUMMY, /**< invalid use of the XPath dummy node */
1727 LYVE_XPATH_NOEND, /**< unterminated string */
Michal Vasko6fae1362016-03-11 15:10:00 +01001728
1729 LYVE_PATH_INCHAR, /**< invalid characters (path) */
Michal Vaskoe733d682016-03-14 09:08:27 +01001730 LYVE_PATH_INMOD, /**< invalid module name (path) */
1731 LYVE_PATH_MISSMOD, /**< missing module name (path) */
Michal Vasko6fae1362016-03-11 15:10:00 +01001732 LYVE_PATH_INNODE, /**< invalid node name (path) */
Michal Vasko6fae1362016-03-11 15:10:00 +01001733 LYVE_PATH_INKEY, /**< invalid key name (path) */
1734 LYVE_PATH_MISSKEY, /**< missing some list keys (path) */
1735 LYVE_PATH_EXISTS, /**< target node already exists (path) */
1736 LYVE_PATH_MISSPAR, /**< some parent of the target node is missing (path) */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001737} LY_VECODE;
Radek Krejcia37b39c2016-03-09 16:38:18 +01001738
1739/**
Radek Krejci7d9f46a2016-01-29 13:53:18 +01001740 * @cond INTERNAL
Radek Krejci386714d2016-02-15 10:24:30 +01001741 * Get address of (thread-specific) `ly_errno' variable.
Radek Krejci26715a42015-07-29 14:10:45 +02001742 */
Radek Krejci7d9f46a2016-01-29 13:53:18 +01001743LY_ERR *ly_errno_location(void);
1744
Michal Vaskof5035ce2016-03-11 10:21:31 +01001745LY_VECODE *ly_vecode_location(void);
Radek Krejcia37b39c2016-03-09 16:38:18 +01001746
Radek Krejci7d9f46a2016-01-29 13:53:18 +01001747/**
1748 * @endcond INTERNAL
Radek Krejcidef50022016-02-01 16:38:32 +01001749 * @brief libyang specific (thread-safe) errno (see #LY_ERR for the list of possible values and their meaning).
Radek Krejci7d9f46a2016-01-29 13:53:18 +01001750 */
1751#define ly_errno (*ly_errno_location())
Radek Krejci9b4ca392015-04-10 08:31:27 +02001752
Radek Krejci386714d2016-02-15 10:24:30 +01001753/**
Radek Krejcia37b39c2016-03-09 16:38:18 +01001754 * @brief libyang's validation error code
1755 */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001756#define ly_vecode (*ly_vecode_location())
Radek Krejcia37b39c2016-03-09 16:38:18 +01001757
1758/**
Michal Vasko13661142016-04-11 10:53:53 +02001759 * @brief Get the last (thread-specific) error message. If the coresponding module defined
1760 * a specific error message, it will be used instead the default one.
Radek Krejci6e8fc0b2016-02-16 14:33:37 +01001761 *
1762 * Sometimes, the error message is extended with path of the element where is the problem.
1763 * The path is available via ly_errpath().
1764 *
Radek Krejcib50551c2016-04-19 09:15:38 +02001765 * @return Text of the last error message, empty string if there is no error.
Radek Krejci386714d2016-02-15 10:24:30 +01001766 */
1767const char *ly_errmsg(void);
1768
Radek Krejci6e8fc0b2016-02-16 14:33:37 +01001769/**
1770 * @brief Get the last (thread-specific) path of the element where was an error.
1771 *
1772 * The path always corresponds to the error message available via ly_errmsg(), so
1773 * whenever a subsequent error message is printed, the path is erased or rewritten.
Radek Krejci3cc10962016-04-13 15:03:27 +02001774 * The path reflects the type of the processed tree - data path for data tree functions
1775 * and schema path in case of schema tree functions. In case of processing YIN schema
1776 * or XML data, the path can be just XML path. In such a case, the corresponding
1777 * ly_vecode (value 1-3) is set.
Radek Krejci6e8fc0b2016-02-16 14:33:37 +01001778 *
Radek Krejcib50551c2016-04-19 09:15:38 +02001779 * @return Path of the error element, empty string if error path does not apply to the last error.
Radek Krejci6e8fc0b2016-02-16 14:33:37 +01001780 */
1781const char *ly_errpath(void);
1782
Michal Vasko13661142016-04-11 10:53:53 +02001783/**
1784 * @brief Get the last (thread-specific) error-app-tag if there was a specific one defined
1785 * in the module for the last error.
1786 *
1787 * The app-tag always corresponds to the error message available via ly_errmsg(), so
1788 * whenever a subsequent error message is printed, the app-tag is erased or rewritten.
1789 *
Radek Krejcib50551c2016-04-19 09:15:38 +02001790 * @return Error-app-tag of the last error, empty string if the error-app-tag does not apply to the last error.
Michal Vasko13661142016-04-11 10:53:53 +02001791 */
1792const char *ly_errapptag(void);
1793
Radek Krejci3045cf32015-05-28 10:58:52 +02001794/**@} logger */
Radek Krejci9b4ca392015-04-10 08:31:27 +02001795
Radek Krejci39d8d0d2015-08-17 13:42:45 +02001796#ifdef __cplusplus
1797}
1798#endif
1799
Radek Krejci9b4ca392015-04-10 08:31:27 +02001800#endif /* LY_LIBYANG_H_ */