blob: 73b3dd2371765a1e971ab053e66e5a16af10d0c9 [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 Krejcidef50022016-02-01 16:38:32 +01006 * Copyright (c) 2015-2016 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 Krejci26715a42015-07-29 14:10:45 +020029/**
Radek Krejcidef50022016-02-01 16:38:32 +010030 * @mainpage About
31 *
32 * libyang is a library implementing processing of the YANG schemas and data modeled by the YANG language. The
33 * library is implemented in C for GNU/Linux and provides C API.
34 *
35 * @section about-features Main Features
36 *
Radek Krejcib4e72e52016-04-13 15:10:51 +020037 * - Parsing (and validating) schemas in YANG format.
Radek Krejcidef50022016-02-01 16:38:32 +010038 * - Parsing (and validating) schemas in YIN format.
39 * - Parsing, validating and printing instance data in XML format.
Radek Krejci3c73f492016-09-20 16:29:30 +020040 * - Parsing, validating and printing instance data in JSON format ([RFC 7951](https://tools.ietf.org/html/rfc7951)).
Radek Krejcidef50022016-02-01 16:38:32 +010041 * - Manipulation with the instance data.
Radek Krejci3c73f492016-09-20 16:29:30 +020042 * - Support for default values in the instance data ([RFC 6243](https://tools.ietf.org/html/rfc6243)).
Radek Krejcidef50022016-02-01 16:38:32 +010043 *
Radek Krejci3c73f492016-09-20 16:29:30 +020044 * The current implementation covers YANG 1.0 [RFC 6020](https://tools.ietf.org/html/rfc6020) as well as
45 * [YANG 1.1](https://tools.ietf.org/html/rfc7950).
Radek Krejci8b13fc02016-04-18 13:08:04 +020046 *
Radek Krejcidef50022016-02-01 16:38:32 +010047 * @subsection about-features-others Extra (side-effect) Features
48 *
49 * - XML parser.
50 * - Optimized string storage (dictionary).
51 *
52 * @section about-license License
53 *
54 * Copyright (c) 2015-2016 CESNET, z.s.p.o.
55 *
56 * (The BSD 3-Clause License)
57 *
58 * Redistribution and use in source and binary forms, with or without
59 * modification, are permitted provided that the following conditions
60 * are met:
61 * 1. Redistributions of source code must retain the above copyright
62 * notice, this list of conditions and the following disclaimer.
63 * 2. Redistributions in binary form must reproduce the above copyright
64 * notice, this list of conditions and the following disclaimer in
65 * the documentation and/or other materials provided with the
66 * distribution.
67 * 3. Neither the name of the Company nor the names of its contributors
68 * may be used to endorse or promote products derived from this
69 * software without specific prior written permission.
70 */
71
72/**
Radek Krejci26715a42015-07-29 14:10:45 +020073 * @page howto How To ...
74 *
75 * - @subpage howtocontext
Radek Krejcid9ba3e32015-07-30 15:08:18 +020076 * - @subpage howtoschemas
77 * - @subpage howtodata
Michal Vasko0f14ba62016-03-21 15:38:11 +010078 * - @subpage howtoxpath
Radek Krejcidef50022016-02-01 16:38:32 +010079 * - @subpage howtoxml
80 * - @subpage howtothreads
Radek Krejci26715a42015-07-29 14:10:45 +020081 * - @subpage howtologger
82 */
Radek Krejcida04f4a2015-05-21 12:54:09 +020083
Radek Krejci26715a42015-07-29 14:10:45 +020084/** @page howtocontext Context
85 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +020086 * The context concept allows callers to work in environments with different sets of YANG schemas.
Radek Krejci26715a42015-07-29 14:10:45 +020087 *
88 * The first step in libyang is to create a new context using ly_ctx_new(). It returns a handler
89 * used in the following work.
90 *
91 * When creating a new context, search dir can be specified (NULL is accepted) to provide directory
92 * where libyang will automatically search for schemas being imported or included. The search path
Radek Krejci1fbe8582016-09-15 09:40:11 +020093 * can be later changed via ly_ctx_set_searchdir() function. If the search dir is specified, it is explored
94 * first. In case the module is not found, libyang tries to find the (sub)module also in current working working
95 * directory. This automatic searching can be completely avoided when the caller sets module searching callback
Radek Krejcidef50022016-02-01 16:38:32 +010096 * (#ly_module_clb) via ly_ctx_set_module_clb().
Radek Krejci26715a42015-07-29 14:10:45 +020097 *
Radek Krejcif6ab2cd2016-04-18 17:15:26 +020098 * Schemas are added into the context using [parser functions](@ref howtoschemasparsers) - \b lys_parse_*().
Radek Krejcidef50022016-02-01 16:38:32 +010099 * In case of schemas, also ly_ctx_load_module() can be used - in that case the #ly_module_clb or automatic
Radek Krejci1fbe8582016-09-15 09:40:11 +0200100 * search in search dir and in the current working directory is used.
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200101 *
102 * Similarly, data trees can be parsed by \b lyd_parse_*() functions. Note, that functions for schemas have \b lys_
Radek Krejcidef50022016-02-01 16:38:32 +0100103 * prefix while functions for instance data have \b lyd_ prefix.
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200104 *
Radek Krejciee674072016-09-15 10:37:40 +0200105 * Context can hold multiple revisions of the same schema, but only one of them can be implemented. The schema is not
106 * implemented in case it is automatically loaded as import for another module and it is not referenced in such
107 * a module (and no other) as target of leafref, augment or deviation. All modules with deviation definition are always
108 * marked as implemented. The imported (not implemented) module can be set implemented by lys_set_implemented(). But
109 * the implemented module cannot be changed back to just imported module. The imported modules are used only as a
110 * source of definitions for types (including identities) and uses statements. The data in such a modules are
111 * ignored - caller is not allowed to create the data defined in the model via data parsers, the default nodes are
112 * not added into any data tree and mandatory nodes are not checked in the data trees.
Radek Krejci26715a42015-07-29 14:10:45 +0200113 *
Radek Krejci31fb8be2016-06-23 15:26:26 +0200114 * Context holds all modules and their submodules internally. To get
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200115 * 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 +0200116 * 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 +0200117 * submodules in the context, it is advised to iterate over them using ly_ctx_get_module_iter(), it is
118 * the most efficient way. Alternatively, the ly_ctx_info() function can be used to get complex information
119 * about the schemas in the context in the form of data tree defined by
Radek Krejcibd9e8d22016-02-03 14:11:48 +0100120 * <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 +0200121 * 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 +0200122 *
123 * Modules held by a context cannot be removed one after one. The only way how to \em change modules in the
124 * context is to create a new context and remove the old one. To remove a context, there is ly_ctx_destroy()
125 * function.
126 *
Radek Krejcidef50022016-02-01 16:38:32 +0100127 * - @subpage howtocontextdict
128 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200129 * \note API for this group of functions is available in the [context module](@ref context).
130 *
Radek Krejcidef50022016-02-01 16:38:32 +0100131 * Functions List
132 * --------------
133 * - ly_ctx_new()
134 * - ly_ctx_set_searchdir()
135 * - ly_ctx_get_searchdir()
136 * - ly_ctx_set_module_clb()
137 * - ly_ctx_get_module_clb()
138 * - ly_ctx_load_module()
139 * - ly_ctx_info()
Michal Vaskod7957c02016-04-01 10:27:26 +0200140 * - ly_ctx_get_module_iter()
Radek Krejcidef50022016-02-01 16:38:32 +0100141 * - ly_ctx_get_module()
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200142 * - ly_ctx_get_module_older()
Radek Krejcidef50022016-02-01 16:38:32 +0100143 * - ly_ctx_get_module_by_ns()
Radek Krejcidef50022016-02-01 16:38:32 +0100144 * - ly_ctx_get_submodule()
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200145 * - ly_ctx_get_submodule2()
Michal Vasko3edeaf72016-02-11 13:17:43 +0100146 * - ly_ctx_get_node()
Radek Krejcidef50022016-02-01 16:38:32 +0100147 * - ly_ctx_destroy()
Radek Krejciee674072016-09-15 10:37:40 +0200148 * - lys_set_implemented()
Radek Krejcidef50022016-02-01 16:38:32 +0100149 */
150
151/**
152 * @page howtocontextdict Context Dictionary
153 *
154 * Context includes dictionary to store strings more effectively. The most of strings repeats quite often in schema
155 * as well as data trees. Therefore, instead of allocating those strings each time they appear, libyang stores them
156 * as records in the dictionary. The basic API to the context dictionary is public, so even a caller application can
157 * use the dictionary.
158 *
159 * To insert a string into the dictionary, caller can use lydict_insert() (adding a constant string) or
160 * lydict_insert_zc() (for dynamically allocated strings that won't be used by the caller after its insertion into
161 * the dictionary). Both functions return the pointer to the inserted string in the dictionary record.
162 *
163 * To remove (reference of the) string from the context dictionary, lydict_remove() is supposed to be used.
164 *
165 * \note Incorrect usage of the dictionary can break libyang functionality.
166 *
167 * \note API for this group of functions is described in the [XML Parser module](@ref dict).
168 *
169 * Functions List
170 * --------------
171 * - lydict_insert()
172 * - lydict_insert_zc()
173 * - lydict_remove()
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200174 */
175
176/**
177 * @page howtoschemas Schemas
178 *
Radek Krejcidef50022016-02-01 16:38:32 +0100179 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200180 * Schema is an internal libyang's representation of a YANG data model. Each schema is connected with
Radek Krejcidef50022016-02-01 16:38:32 +0100181 * its [context](@ref howtocontext) and loaded using [parser functions](@ref howtoschemasparsers). It means, that
182 * the schema cannot be created (nor changed) programmatically. In libyang, schemas are used only to
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200183 * access data model definitions.
184 *
Radek Krejcidef50022016-02-01 16:38:32 +0100185 * Schema tree nodes are able to hold private objects (via a pointer to a structure, function, variable, ...) used by
186 * a caller application. Such an object can be assigned to a specific node using lys_set_private() function.
187 * Note that the object is not freed by libyang when the context is being destroyed. So the caller is responsible
188 * 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 +0200189 * appropriate schema nodes where the object was previously set. This can be automated via destructor function
190 * to free these private objects. The destructor is passed to the ly_ctx_destroy() function. On the other hand,
191 * freeing the object while the schema tree is still in use can lead to a segmentation fault.
Radek Krejcidef50022016-02-01 16:38:32 +0100192 *
193 * - @subpage howtoschemasparsers
194 * - @subpage howtoschemasfeatures
195 * - @subpage howtoschemasprinters
196 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200197 * \note There are many functions to access information from the schema trees. Details are available in
198 * the [Schema Tree module](@ref schematree).
199 *
Radek Krejciee674072016-09-15 10:37:40 +0200200 * For information about difference between implemented and imported modules, see the
201 * [context description](@ref howtocontext).
202 *
Radek Krejcidef50022016-02-01 16:38:32 +0100203 * Functions List (not assigned to above subsections)
204 * --------------------------------------------------
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200205 * - lys_getnext()
Radek Krejcidef50022016-02-01 16:38:32 +0100206 * - lys_parent()
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200207 * - lys_module()
208 * - lys_node_module()
Radek Krejcidef50022016-02-01 16:38:32 +0100209 * - lys_set_private()
Radek Krejciee674072016-09-15 10:37:40 +0200210 * - lys_set_implemented()
Radek Krejcidef50022016-02-01 16:38:32 +0100211 */
212
213/**
214 * @page howtoschemasparsers Parsing Schemas
215 *
216 * Schema parser allows to read schema from a specific format. libyang supports the following schema formats:
217 *
218 * - YANG
219 *
220 * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020).
221 * Currently, only YANG 1.0 is supported.
222 *
Radek Krejcidef50022016-02-01 16:38:32 +0100223 * - YIN
224 *
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200225 * Alternative XML-based format to YANG - YANG Independent Notation. The details can be found in
Radek Krejcidef50022016-02-01 16:38:32 +0100226 * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11).
227 *
228 * When the [context](@ref howtocontext) is created, it already contains the following three schemas, which
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200229 * are implemented internally by libyang:
Radek Krejcidef50022016-02-01 16:38:32 +0100230 * - ietf-inet-types@2013-07-15
231 * - ietf-yang-types@2013-07-15
232 * - ietf-yang-library@2015-07-03
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200233 * - yang@2016-02-11
234 *
235 * The last one is libyang's internal module to provide namespace for various YANG attributes defined in RFC 6020
236 * (such as `insert` attribute for edit-config's data).
Radek Krejcidef50022016-02-01 16:38:32 +0100237 *
238 * Other schemas can be added to the context manually as described in [context page](@ref howtocontext) by the functions
239 * listed below. Besides the schema parser functions, it is also possible to use ly_ctx_load_module() which tries to
240 * find the required schema automatically - using #ly_module_clb or automatic search in working directory and in the
241 * context's searchpath.
242 *
243 * Functions List
244 * --------------
Radek Krejci722b0072016-02-01 17:09:45 +0100245 * - lys_parse_mem()
Radek Krejcidef50022016-02-01 16:38:32 +0100246 * - lys_parse_fd()
247 * - lys_parse_path()
248 * - ly_ctx_set_module_clb()
249 * - ly_ctx_load_module()
250 */
251
252/**
253 * @page howtoschemasfeatures YANG Features Manipulation
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200254 *
255 * The group of functions prefixed by \b lys_features_ are used to access and manipulate with the schema's
256 * features.
257 *
258 * The first two functions are used to access information about the features in the schema.
259 * lys_features_list() provides list of all features defined in the specific schema and its
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200260 * submodules. Optionally, it can also provide information about the state of all features.
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200261 * Alternatively, caller can use lys_features_state() function to get state of one specific
262 * feature.
263 *
264 * The remaining two functions, lys_features_enable() and lys_features_disable(), are used
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200265 * to enable and disable the specific feature (or all via the '`*`' value). By default, when the module
Radek Krejcidef50022016-02-01 16:38:32 +0100266 * is loaded by libyang parser, all features are disabled.
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200267 *
Radek Krejcidef50022016-02-01 16:38:32 +0100268 * 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 +0200269 *
Radek Krejcidef50022016-02-01 16:38:32 +0100270 * Note, that the feature's state can affect some of the output formats (e.g. Tree format).
271 *
272 * Functions List
273 * --------------
274 * - lys_features_list()
275 * - lys_features_enable()
276 * - lys_features_disable()
277 * - lys_features_state()
278 * - lys_is_disabled()
279 */
280
281/**
282 * @page howtoschemasprinters Printing Schemas
283 *
284 * Schema printers allows to serialize internal representation of a schema module in a specific format. libyang
285 * supports the following schema formats for printing:
286 *
287 * - YANG
288 *
289 * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020).
290 * Currently, only YANG 1.0 is supported.
291 *
292 * - YIN
293 *
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200294 * Alternative XML-based format to YANG - YANG Independent Notation. The details can be found in
Radek Krejcidef50022016-02-01 16:38:32 +0100295 * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11).
296 *
Radek Krejcidef50022016-02-01 16:38:32 +0100297 * - Tree
298 *
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200299 * Simple tree structure of the module where each node is printed as:
300 *
301 * <status> <flags> <name> <opts> <type> <if-features>
302 *
303 * - `<status>` is one of:
304 * - `+` for current
305 * - `x` for deprecated
306 * - `o` for obsolete
307 *
308 * - `<flags>` is one of:
309 * - `rw` for configuration data
310 * - `ro` for status data
311 * - `-x` for RPCs
312 * - `-n` for Notification
313 *
314 * - `<name>` is the name of the node
315 * - `(<name>)` means that the node is a choice node
316 * - `:(<name>)` means that the node is a case node
317 * - if the node is augmented into the tree from another module, it is printed with the module name as
318 * `<module-name>:<name>`.
319 *
320 * - `<opts>` is one of:
321 * - `?` for an optional leaf or choice
322 * - `!` for a presence container
323 * - `*` for a leaf-list or list
324 * - `[<keys>]` for a list's keys
325 *
326 * - `<type>` is the name of the type for leafs and leaf-lists
327 * - if there is a default value defined, it is printed within angle brackets `<default-value>`
328 * - if the type is a leafref, the type is printed as -> TARGET`
329 *
330 * - `<if-features>` is the list of features this node depends on, printed within curly brackets and
331 * a question mark `{...}?`
332 *
Radek Krejcidef50022016-02-01 16:38:32 +0100333 *
334 * - Info
335 *
336 * Detailed information about the specific node in the schema tree.
337 * It allows to print information not only about a specific module, but also about its specific part:
338 *
339 * - absolute-schema-nodeid
340 *
341 * e.g. \a `/modules/module-set-id` in \a `ietf-yang-library` module
342 *
343 * - <b>typedef/</b>typedef-name
344 *
345 * e.g. \a `typedef/revision-identifier` in \a `ietf-yang-library` module
346 *
347 * - <b>feature/</b>feature-name
348 *
349 * e.g. \a `feature/ssh` in \a `ietf-netconf-server` module
350 *
351 * - <b>grouping/</b>grouping-name/descendant-schema-nodeid
352 *
353 * e.g. \a `grouping/module` or \a `grouping/module/module/submodules` in \a `ietf-yang-library` module
354 *
355 * - <b>type/</b>leaf-or-leaflist
356 *
357 * e.g. \a `type/modules/module-set-id` in \a `ietf-yang-library` module
358 *
359 * Printer functions allow to print to the different outputs including a callback function which allows caller
360 * to have a full control of the output data - libyang passes to the callback a private argument (some internal
361 * data provided by a caller of lys_print_clb()), string buffer and number of characters to print. Note that the
362 * callback is supposed to be called multiple times during the lys_print_clb() execution.
363 *
364 * Functions List
365 * --------------
366 * - lys_print_mem()
367 * - lys_print_fd()
368 * - lys_print_file()
369 * - lys_print_clb()
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200370 */
371
372/**
373 * @page howtodata Data Instances
Radek Krejci26715a42015-07-29 14:10:45 +0200374 *
Radek Krejcidef50022016-02-01 16:38:32 +0100375 * All data nodes in data trees are connected with their schema node - libyang is not able to represent data of an
376 * unknown schema.
377 *
Michal Vasko1ec579e2016-09-13 11:24:28 +0200378 * 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 +0100379 *
380 * - @subpage howtodataparsers
381 * - @subpage howtodatamanipulators
Michal Vasko1ec579e2016-09-13 11:24:28 +0200382 * - @subpage howtodatavalidation
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200383 * - @subpage howtodatawd
Radek Krejcidef50022016-02-01 16:38:32 +0100384 * - @subpage howtodataprinters
385 *
386 * \note API for this group of functions is described in the [Data Instances module](@ref datatree).
387 *
388 * Functions List (not assigned to above subsections)
389 * --------------------------------------------------
Michal Vaskof06fb5b2016-09-08 10:05:56 +0200390 * - lyd_find_instance()
391 * - lyd_find_xpath()
Radek Krejciae1c3b12016-09-20 16:30:32 +0200392 * - lyd_leaf_type()
Radek Krejcidef50022016-02-01 16:38:32 +0100393 */
394
395/**
396 * @page howtodataparsers Parsing Data
397 *
398 * Data parser allows to read instances from a specific format. libyang supports the following data formats:
399 *
400 * - XML
401 *
402 * Original data format used in NETCONF protocol. XML mapping is part of the YANG specification
403 * ([RFC 6020](http://tools.ietf.org/html/rfc6020)).
404 *
405 * - JSON
406 *
407 * The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG
408 * can be found in [this draft](https://tools.ietf.org/html/draft-ietf-netmod-yang-json-05).
409 *
410 * Besides the format of input data, the parser functions accepts additional [options](@ref parseroptions) to specify
411 * how the input data should be processed.
412 *
413 * In contrast to the schema parser, data parser also accepts empty input data if such an empty data tree is valid
414 * according to the schemas in the libyang context.
415 *
416 * In case of XML input data, there is one additional way to parse input data. Besides parsing the data from a string
417 * in memory or a file, caller is able to build an XML tree using [libyang XML parser](@ref howtoxml) and then use
418 * this tree (or a part of it) as input to the lyd_parse_xml() function.
419 *
420 * Functions List
421 * --------------
Radek Krejci722b0072016-02-01 17:09:45 +0100422 * - lyd_parse_mem()
Radek Krejcidef50022016-02-01 16:38:32 +0100423 * - lyd_parse_fd()
424 * - lyd_parse_path()
425 * - lyd_parse_xml()
426 */
427
428/**
429 * @page howtodatamanipulators Manipulating Data
430 *
431 * There are many functions to create or modify an existing data tree. You can add new nodes, reconnect nodes from
432 * one tree to another (or e.g. from one list instance to another) or remove nodes. The functions doesn't allow you
433 * to put a node to a wrong place (by checking the module), but not all validation checks can be made directly
434 * (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 +0100435 * there is lyd_validate() function supposed to be called to make sure that the current data tree is valid. If
436 * working with RPCs, they are invalid also in case the data nodes are not ordered according to the schema, which
437 * you can fix easily with lyd_schema_sort(). Note, that not performing validation after some data tree changes
438 * can cause failure of various libyang functions later.
Radek Krejcidef50022016-02-01 16:38:32 +0100439 *
Michal Vasko0f14ba62016-03-21 15:38:11 +0100440 * 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 +0200441 * 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 +0100442 * address the nodes using a simple XPath addressing (lyd_new_path()). The latter enables to create a whole path
443 * of nodes, requires less information about the modified data, and is generally simpler to use. The path format
444 * specifics can be found [here](@ref howtoxpath).
Michal Vasko0f14ba62016-03-21 15:38:11 +0100445 *
Michal Vasko3c126822016-09-22 13:48:42 +0200446 * Working with two data subtrees can also be performed two ways. Usually, you would use lyd_insert*() functions.
447 * They are generally meant for simple inserts of a node into a data tree. For more complicated inserts and when
448 * merging 2 trees use lyd_merge(). It offers additional options and is basically a more powerful insert.
Michal Vasko45fb2822016-04-18 13:32:17 +0200449 *
Radek Krejcidef50022016-02-01 16:38:32 +0100450 * Also remember, that when you are creating/inserting a node, all the objects in that operation must belong to the
451 * same context.
452 *
453 * Modifying the single data tree in multiple threads is not safe.
454 *
455 * Functions List
456 * --------------
457 * - lyd_dup()
458 * - lyd_change_leaf()
459 * - lyd_insert()
Radek Krejcidb6b1662016-09-15 10:40:16 +0200460 * - lyd_insert_sibling()
Radek Krejcidef50022016-02-01 16:38:32 +0100461 * - lyd_insert_before()
462 * - lyd_insert_after()
463 * - lyd_insert_attr()
Michal Vasko45fb2822016-04-18 13:32:17 +0200464 * - lyd_merge()
Radek Krejcidef50022016-02-01 16:38:32 +0100465 * - lyd_new()
Michal Vasko0845b112016-09-08 10:07:08 +0200466 * - lyd_new_anydata()
Radek Krejcidef50022016-02-01 16:38:32 +0100467 * - lyd_new_leaf()
Michal Vaskof5299282016-03-16 13:32:02 +0100468 * - lyd_new_path()
Michal Vasko0ba46152016-05-11 14:16:55 +0200469 * - lyd_new_output()
Michal Vasko0845b112016-09-08 10:07:08 +0200470 * - lyd_new_output_anydata()
Michal Vasko0ba46152016-05-11 14:16:55 +0200471 * - lyd_new_output_leaf()
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200472 * - lyd_schema_sort()
Radek Krejcidef50022016-02-01 16:38:32 +0100473 * - lyd_unlink()
474 * - lyd_free()
475 * - lyd_free_attr()
476 * - lyd_free_withsiblings()
Michal Vasko1ec579e2016-09-13 11:24:28 +0200477 */
478
479/**
480 * @page howtodatavalidation Validating Data
481 *
482 * By default, the represented data are supposed to represent a full YANG datastore content. So if a schema declares
483 * some mandatory nodes, despite configuration or status, the data are supposed to be present in the data tree being
484 * loaded or validated. However, it is possible to specify other kinds of data (see @ref parseroptions) allowing some
485 * exceptions to the validation process.
486 *
487 * Data validation is performed implicitly to the input data processed by the parser (\b lyd_parse_*() functions) and
488 * on demand via the lyd_validate() function. The lyd_validate() is supposed to be used when a (complex or simple)
489 * change is done on the data tree (via a combination of \b lyd_change_*(), \b lyd_insert*(), \b lyd_new*(),
490 * lyd_unlink() and lyd_free() functions).
491 *
492 * Must And When Conditions Accessible Tree
493 * ----------------------------------------
494 *
495 * In YANG 1.1, there can be \b must and/or \b when expressions in RPC/action input or output, or in notifications that
496 * require access to the configuration datastore and/or state data. Normally, when working with any of the aforementioned
497 * data trees, they must contain only the RPC/action/notification itself, without any additional configuration or state
498 * data. So how can then these conditions be verified during validation?
499 *
500 * There is an option to pass this additional data tree to all the functions that perform \b must and \b when condition
501 * checking (\b lyd_parse_*() and lyd_validate()). Also, there is a flag #LYS_XPATH_DEP of \b struct lys_node that
502 * marks schema nodes that include conditions that require foreign nodes (outside their subtree) for their evaluation.
503 * The subtree root is always the particular operation data node (for RPC it is the RPC data node and all
504 * the input or output nodes as its children and similarly for action and notification). Note that for action and
505 * not-top-level notification this means that all their parents are not considered as belonging to their subtree even though
506 * they are included in their data tree and must be present for the operation validation to pass. The reason for this is that if
507 * there are any lists in those parents, we cannot know if there are not some other instances of them in the standard
508 * data tree in addition to the one used in the action/notification invocation.
509 *
510 * There were 2 ways of using this mechanism envisioned (explained below), but you can combine or modify them.
511 *
512 * ### Fine-grained Data Retrieval ###
513 *
514 * This approach is recommended when you do not maintain a full configuration data tree with state data at all times.
515 *
516 * Firstly, you should somehow learn that the operation data tree you are currently working with includes some schema
517 * node instances that have conditions that require foreign data. You can either know this about every operation beforehand
518 * or you go through all the schema nodes looking for the flag #LYS_XPATH_DEP. Then you should use lys_node_xpath_atomize()
519 * to retrieve all XPath condition dependencies (in the form of schema nodes) outside the operation subtree. You will likely
520 * want to use the flag #LYXP_NO_LOCAL to get rid of all the nodes from inside the subtree (you should already have those).
521 * 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()
522 * (it will be expected). Then you pass this tree to the validation and it should now have access to all the nodes that
523 * can potentially affect the XPath evaluation and no other.
524 *
525 * ### Maintaining Configuration And State Data Tree ###
526 *
527 * If you have a full data tree with state data available for the validation process then it is quite simple (compared
528 * to the first approach). You can simply always pass it to validation of these operations and in cases it is not required
529 * (no nodes with conditions traversing foreign nodes) only a negligible amount of redundant work is performed and you can
530 * skip the process of learning whether it is required or not.
531 *
532 * Functions List
533 * --------------
Radek Krejcidef50022016-02-01 16:38:32 +0100534 * - lyd_validate()
535 */
536
537/**
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200538 * @page howtodatawd Default Values
539 *
Radek Krejcidb6b1662016-09-15 10:40:16 +0200540 * 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 +0200541 * 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 +0200542 * - \b explicit - Only the explicitly set configuration data. But in the case of status data, missing default
Radek Krejci46180b52016-08-31 16:01:32 +0200543 * data are added into the tree. In libyang, this mode is represented by #LYP_WD_EXPLICIT option.
544 * - \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 +0200545 * - \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 +0200546 * #LYP_WD_ALL option.
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200547 * - \b report-all-tagged - In this case, all the missing default data are added as in case of the `report-all` mode,
548 * but additionally all the nodes (existing as well as added) containing the schema default value
Radek Krejci46180b52016-08-31 16:01:32 +0200549 * are tagged (see the note below). libyang uses #LYP_WD_ALL_TAG option for this mode.
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200550 * - \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 +0200551 * This is the libyang's extension and it is represented by #LYP_WD_IMPL_TAG option.
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200552 *
Radek Krejci46180b52016-08-31 16:01:32 +0200553 * libyang automatically adds/maintain the default nodes when a data tree is being parsed or validated. Note, that in a
554 * modified data tree (via e.g. lys_insert() or lys_free()), some of the default nodes can be missing or they can be
555 * present by mistake. Such a data tree is again corrected during the next lyd_validate() call.
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200556 *
Radek Krejci46180b52016-08-31 16:01:32 +0200557 * 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 +0200558 * leafs and leaf-lists. In case of containers, the flag means that the container holds only a default node(s) or it
559 * 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 +0200560 *
Radek Krejci46180b52016-08-31 16:01:32 +0200561 * The presence of the default nodes during the data tree lifetime is affected by the LYD_OPT_ flag used to
562 * parse/validate the tree:
563 * - #LYD_OPT_DATA - all the default nodes are present despite they are configuration or status nodes
564 * - #LYD_OPT_CONFIG - only the configuration data nodes are added into the tree
565 * - #LYD_OPT_GET, #LYD_OPT_GETCONFIG, #LYD_OPT_EDIT - no default nodes are added
566 * - #LYD_OPT_RPC, #LYD_OPT_RPCREPLY, #LYD_OPT_NOTIF - the default nodes from the particular subtree are added
567 *
Radek Krejcidb6b1662016-09-15 10:40:16 +0200568 * The with-default modes described above are supported when the data tree is being printed with the
Radek Krejci46180b52016-08-31 16:01:32 +0200569 * [LYP_WD_ printer flags](@ref printerflags). Note, that in case of #LYP_WD_ALL_TAG and #LYP_WD_IMPL_TAG modes,
570 * 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 +0200571 * these modes have the same result as #LYP_WD_ALL. The presence of empty containers (despite they were added explicitly
572 * or implicitly as part of accessible data tree) depends on #LYP_KEEPEMPTYCONT option.
Radek Krejci46180b52016-08-31 16:01:32 +0200573 *
574 * 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 +0200575 * use lyd_wd_default() function.
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200576 *
577 * Functions List
578 * --------------
Radek Krejci46180b52016-08-31 16:01:32 +0200579 * - lyd_wd_default()
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200580 *
581 * - lyd_parse_mem()
582 * - lyd_parse_fd()
583 * - lyd_parse_path()
584 * - lyd_parse_xml()
585 * - lyd_validate()
Radek Krejci46180b52016-08-31 16:01:32 +0200586 * - lyd_print_mem()
587 * - lyd_print_fd()
588 * - lyd_print_file()
589 * - lyd_print_clb()
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200590 */
591
592/**
Radek Krejcidef50022016-02-01 16:38:32 +0100593 * @page howtodataprinters Printing Data
594 *
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200595 * Data printers allows to serialize internal representation of a data tree in a specific format. libyang
596 * supports the following data formats for printing:
Radek Krejcidef50022016-02-01 16:38:32 +0100597 *
598 * - XML
599 *
600 * Basic format as specified in rules of mapping YANG modeled data to XML in
601 * [RFC 6020](http://tools.ietf.org/html/rfc6020). It is possible to specify if
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200602 * the indentation (formatting) will be used (by #LYP_FORMAT @ref printerflags "printer option").
Radek Krejcidef50022016-02-01 16:38:32 +0100603 *
604 * - JSON
605 *
606 * The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG
Radek Krejcif6ab2cd2016-04-18 17:15:26 +0200607 * can be found in [this draft](https://tools.ietf.org/html/draft-ietf-netmod-yang-json-05).It is possible to specify
608 * if the indentation (formatting) will be used (by #LYP_FORMAT @ref printerflags "printer option").
Radek Krejcidef50022016-02-01 16:38:32 +0100609 *
610 * Printer functions allow to print to the different outputs including a callback function which allows caller
611 * to have a full control of the output data - libyang passes to the callback a private argument (some internal
612 * data provided by a caller of lyd_print_clb()), string buffer and number of characters to print. Note that the
613 * callback is supposed to be called multiple times during the lyd_print_clb() execution.
614 *
Radek Krejci46180b52016-08-31 16:01:32 +0200615 * To print the data tree with default nodes according to the with-defaults capability defined in
616 * [RFC 6243](https://tools.ietf.org/html/rfc6243), check the [page about the default values](@ref howtodatawd).
617 *
Radek Krejcidef50022016-02-01 16:38:32 +0100618 * Functions List
619 * --------------
620 * - lyd_print_mem()
621 * - lyd_print_fd()
622 * - lyd_print_file()
623 * - lyd_print_clb()
624 */
625
626/**
Radek Krejcib50551c2016-04-19 09:15:38 +0200627 * @page howtoxpath XPath Addressing
628 *
629 * 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 +0200630 * 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 +0200631 * 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 +0200632 * This XPath conforms to the YANG specification (RFC 6020 section 6.4). Some useful examples:
Michal Vasko8e627692016-04-19 12:15:47 +0200633 *
Michal Vaskoebea7012016-04-19 14:15:22 +0200634 * - get all top-level nodes of the __module-name__
635 *
636 * /module-name:*
637 *
638 * - get all the descendants of __container__ (excluding __container__)
639 *
640 * /module-name:container//\asterisk
641 *
642 * - 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__)
643 *
644 * /module-name:container/list[key1='1'][key2='2']
645 *
646 * - get __leaf-list__ instance with the value __val__
647 *
648 * /module-name:container/leaf-list[.='val']
649 *
650 * - get __aug-leaf__, which was added to __module-name__ from an augment module __augment-module__
651 *
652 * /module-name:container/container2/augment-module:aug-cont/aug-leaf
653 *
Radek Krejcib50551c2016-04-19 09:15:38 +0200654 *
655 * A very small subset of this full XPath is recognized by lyd_new_path(). Basically, only a relative or absolute
656 * path can be specified to identify a new data node. However, lists must be identified by all their keys and created
657 * with all of them, so for those cases predicates are allowed. Predicates must be ordered the way the keys are ordered
Michal Vasko1acf8502016-05-05 09:14:07 +0200658 * and all the keys must be specified. Every predicate includes a single key with its value. Optionally, leaves and
659 * leaf-lists can have predicates specifying their value in the path itself. All these paths are valid XPath
Radek Krejcib50551c2016-04-19 09:15:38 +0200660 * expressions. Example:
661 *
Michal Vasko1acf8502016-05-05 09:14:07 +0200662 * /ietf-yang-library:modules-state/module[name='ietf-yang-library'][revision='']/conformance[.='implement']
Radek Krejcib50551c2016-04-19 09:15:38 +0200663 *
664 * Almost the same XPath is accepted by ly_ctx_get_node(). The difference is that it is not used on data, but schema,
665 * which means there are no key values and only one node matches one path. In effect, lists do not have to have any
666 * predicates. If they do, they do not need to have all the keys specified and if values are included, they are ignored.
667 * Nevertheless, any such expression is still a valid XPath, but can return more nodes if executed on a data tree.
668 * Examples (all returning the same node):
669 *
670 * /ietf-yang-library:modules-state/module/submodules
671 * /ietf-yang-library:modules-state/module[name]/submodules
672 * /ietf-yang-library:modules-state/module[name][revision]/submodules
673 * /ietf-yang-library:modules-state/module[name='ietf-yang-library'][revision]/submodules
674 *
675 * 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 +0200676 * lys_find_xpath() if you want to search based on a data XPath.
Radek Krejcib50551c2016-04-19 09:15:38 +0200677 *
678 * Also note, that in all cases the node's prefix is specified as the name of the appropriate YANG schema. Any node
679 * can be prefixed by the module name. However, if the prefix is omitted, the module name is inherited from the previous
680 * (parent) node. It means, that the first node in the path is always supposed to have a prefix.
681 *
682 * Functions List
683 * --------------
Michal Vaskof06fb5b2016-09-08 10:05:56 +0200684 * - lyd_find_xpath()
685 * - lys_find_xpath()
Radek Krejcib50551c2016-04-19 09:15:38 +0200686 * - lyd_new_path()
687 * - ly_ctx_get_node()
Radek Krejcib50551c2016-04-19 09:15:38 +0200688 */
689
690/**
Radek Krejcidef50022016-02-01 16:38:32 +0100691 * @page howtoxml libyang XML Support
692 *
Radek Krejcib50551c2016-04-19 09:15:38 +0200693 * libyang XML parser is able to parse XML documents. The main purpose is to load data modeled by YANG. However, it can
694 * 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 +0100695 * - comments are ignored
696 * - Doctype declaration is ignored
697 * - CData sections are ignored
698 * - Process Instructions (PI) are ignored
699 *
700 * The API is designed to almost only read-only access. You can simply load XML document, go through the tree as
701 * you wish and dump the tree to an output. The only "write" functions are lyxml_free() and lyxml_unlink() to remove
702 * part of the tree or to unlink (separate) a subtree.
703 *
Radek Krejcib50551c2016-04-19 09:15:38 +0200704 * XML parser is used internally by libyang for parsing YIN schemas and data instances in XML format.
Radek Krejcidef50022016-02-01 16:38:32 +0100705 *
706 * \note API for this group of functions is described in the [XML Parser module](@ref xmlparser).
707 *
708 * Functions List
709 * --------------
Radek Krejci722b0072016-02-01 17:09:45 +0100710 * - lyxml_parse_mem()
711 * - lyxml_parse_path()
Radek Krejcidef50022016-02-01 16:38:32 +0100712 * - lyxml_get_attr()
713 * - lyxml_get_ns()
Radek Krejci722b0072016-02-01 17:09:45 +0100714 * - lyxml_print_mem()
715 * - lyxml_print_fd()
716 * - lyxml_print_file()
717 * - lyxml_print_clb()
Radek Krejcidef50022016-02-01 16:38:32 +0100718 * - lyxml_unlink()
719 * - lyxml_free()
720 */
721
722/**
723 * @page howtothreads libyang in Threads
724 *
Radek Krejcib50551c2016-04-19 09:15:38 +0200725 * libyang can be used in multithreaded applications keeping in mind the following rules:
Radek Krejcidef50022016-02-01 16:38:32 +0100726 * - 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 +0200727 * thread before any other work with context, schemas or data instances. Destroying the context is supposed to
Radek Krejcidef50022016-02-01 16:38:32 +0100728 * be done when no other thread accesses context, schemas nor data trees
729 * - Data parser (\b lyd_parse*() functions) can be used simultaneously in multiple threads (also the returned
730 * #ly_errno is thread safe).
731 * - Modifying (lyd_new(), lyd_insert(), lyd_unlink(), lyd_free() and many other functions) a single data tree is not
732 * thread safe.
Radek Krejci26715a42015-07-29 14:10:45 +0200733 */
Radek Krejci94ca54b2015-07-08 15:48:47 +0200734
Radek Krejcida04f4a2015-05-21 12:54:09 +0200735/**
Radek Krejci26715a42015-07-29 14:10:45 +0200736 *
737 * @page howtologger Logger
738 *
739 * There are 4 verbosity levels defined as ::LY_LOG_LEVEL. The level can be
740 * changed by the ly_verb() function. By default, the verbosity level is
741 * set to #LY_LLERR value.
742 *
Radek Krejcib50551c2016-04-19 09:15:38 +0200743 * When an error is encountered, the error message and error number are stored for
744 * later use. Caller is able to access the last error message via ly_errmsg() and the
745 * corresponding last error code via #ly_errno. If that was a validation error (#ly_errno
746 * is set to #LY_EVALID), also validation error code (via #ly_vecode) and path to the
747 * error node (via ly_errpath()) are available.
748 *
749 * For some specific cases, a YANG schema can define error message and/or error tag (mainly for
Michal Vaskoebea7012016-04-19 14:15:22 +0200750 * 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 +0200751 * it is available via ly_erraptag() (if not set, the returned string is empty).
752 *
Michal Vaskoebea7012016-04-19 14:15:22 +0200753 * 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 +0200754 * callback function. In that case, instead of printing messages, libyang passes error level, message and path
755 * (if any) to the caller's callback function. In case of error level, the message and path are still
756 * automatically stored and available via the functions and macros described above.
Radek Krejci26715a42015-07-29 14:10:45 +0200757 *
Radek Krejcidef50022016-02-01 16:38:32 +0100758 * \note API for this group of functions is described in the [logger module](@ref logger).
759 *
760 * Functions List
761 * --------------
762 * - ly_verb()
763 * - ly_set_log_clb()
764 * - ly_get_log_clb()
Radek Krejcib50551c2016-04-19 09:15:38 +0200765 * - ly_errmsg()
766 * - ly_errpath()
767 * - ly_errapptag()
768 * - #ly_errno
769 * - #ly_vecode
Radek Krejci26715a42015-07-29 14:10:45 +0200770 */
771
772/**
773 * @defgroup context Context
Radek Krejci3045cf32015-05-28 10:58:52 +0200774 * @{
775 *
Radek Krejci26715a42015-07-29 14:10:45 +0200776 * Structures and functions to manipulate with the libyang "containers". The \em context concept allows callers
777 * to work in environments with different sets of YANG schemas. More detailed information can be found at
778 * @ref howtocontext page.
Radek Krejci3045cf32015-05-28 10:58:52 +0200779 */
780
781/**
Radek Krejcida04f4a2015-05-21 12:54:09 +0200782 * @brief libyang context handler.
783 */
784struct ly_ctx;
785
786/**
787 * @brief Create libyang context
788 *
Radek Krejci26715a42015-07-29 14:10:45 +0200789 * Context is used to hold all information about schemas. Usually, the application is supposed
Radek Krejci91b833c2015-09-04 11:49:43 +0200790 * to work with a single context in which libyang is holding all schemas (and other internal
791 * information) according to which the data trees will be processed and validated. So, the schema
792 * trees are tightly connected with the specific context and they are held by the context internally
793 * - caller does not need to keep pointers to the schemas returned by lys_parse(), context knows
794 * about them. The data trees created with lyd_parse() are still connected with the specific context,
795 * but they are not internally held by the context. The data tree just points and lean on some data
796 * held by the context (schema tree, string dictionary, etc.). Therefore, in case of data trees, caller
797 * is supposed to keep pointers returned by the lyd_parse() and manage the data tree on its own. This
798 * also affects the number of instances of both tree types. While you can have only one instance of
799 * specific schema connected with a single context, number of data tree instances is not connected.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200800 *
Radek Krejci26715a42015-07-29 14:10:45 +0200801 * @param[in] search_dir Directory where libyang will search for the imported or included modules
802 * and submodules. If no such directory is available, NULL is accepted.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200803 *
Radek Krejci3045cf32015-05-28 10:58:52 +0200804 * @return Pointer to the created libyang context, NULL in case of error.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200805 */
806struct ly_ctx *ly_ctx_new(const char *search_dir);
807
808/**
Michal Vasko60ba9a62015-07-03 14:42:31 +0200809 * @brief Change the search path in libyang context
810 *
811 * @param[in] ctx Context to be modified.
812 * @param[in] search_dir New search path to replace the current one in ctx.
813 */
814void ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir);
815
816/**
Radek Krejci5a797572015-10-21 15:45:45 +0200817 * @brief Get current value of the search path in libyang context
818 *
819 * @param[in] ctx Context to query.
820 * @return Current value of the search path.
821 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100822const char *ly_ctx_get_searchdir(const struct ly_ctx *ctx);
Radek Krejci5a797572015-10-21 15:45:45 +0200823
824/**
Radek Krejci7ab25152015-08-07 14:48:45 +0200825 * @brief Get data of an internal ietf-yang-library module.
826 *
827 * @param[in] ctx Context with the modules.
828 * @return Root data node corresponding to the model, NULL on error.
829 * Caller is responsible for freeing the returned data tree using lyd_free().
830 */
831struct lyd_node *ly_ctx_info(struct ly_ctx *ctx);
832
833/**
Michal Vaskod7957c02016-04-01 10:27:26 +0200834 * @brief Iterate over all modules in a context.
835 *
836 * @param[in] ctx Context with the modules.
837 * @param[in,out] idx Index of the next module to be returned. Value of 0 starts from the beginning.
838 * @return Next context module, NULL if the last was already returned.
839 */
840const struct lys_module *ly_ctx_get_module_iter(const struct ly_ctx *ctx, uint32_t *idx);
841
842/**
Radek Krejcifd4e6e32015-08-10 15:00:51 +0200843 * @brief Get pointer to the schema tree of the module of the specified name.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200844 *
Radek Krejcida04f4a2015-05-21 12:54:09 +0200845 * @param[in] ctx Context to work in.
846 * @param[in] name Name of the YANG module to get.
Radek Krejcif647e612015-07-30 11:36:07 +0200847 * @param[in] revision Optional revision date of the YANG module to get. If not specified,
848 * the schema in the newest revision is returned if any.
849 * @return Pointer to the data model structure, NULL if no schema following the name and
Radek Krejcifd4e6e32015-08-10 15:00:51 +0200850 * revision requirements is present in the context.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200851 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100852const 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 +0200853
854/**
Radek Krejci21601a32016-03-07 11:39:27 +0100855 * @brief Get pointer to the older schema tree to the specified one in the provided context.
856 *
857 * The module is not necessarily from the provided \p ctx. If there are multiple schemas older than the
858 * provided one, the newest of them is returned.
859 *
860 * The function can be used in combination with ly_ctx_get_module() to get all revisions of a module in a context:
861 * \code{.c}
862 * for (mod = ly_ctx_get_module(ctx, name, NULL); mod; mod = ly_ctx_get_module_older(ctx, mod)) {
863 * ...
864 * }
865 * \endcode
866 *
867 * @param[in] ctx Context to work in.
868 * @param[in] module YANG module to compare with
869 * @return Pointer to the data model structure, NULL if no older schema is present in the context.
870 */
871const struct lys_module *ly_ctx_get_module_older(const struct ly_ctx *ctx, const struct lys_module *module);
872
873/**
Michal Vasko99b0aad2015-12-01 12:28:51 +0100874 * @brief Try to find the model in the searchpath of \p ctx and load it into it. If custom missing
875 * module callback is set, it is used instead.
Michal Vasko82465962015-11-10 11:03:11 +0100876 *
Radek Krejci31fb8be2016-06-23 15:26:26 +0200877 * If there is a possibility that the requested module is already in the context, you should call
878 * the ly_ctx_get_module() first to avoid a lot of work performed by ly_ctx_load_module().
879 *
Michal Vasko82465962015-11-10 11:03:11 +0100880 * @param[in] ctx Context to add to.
Michal Vasko82465962015-11-10 11:03:11 +0100881 * @param[in] name Name of the module to load.
882 * @param[in] revision Optional revision date of the module. If not specified, it is
883 * assumed that there is only one model revision in the searchpath (the first matching file
884 * is parsed).
885 * @return Pointer to the data model structure, NULL if not found or some error occured.
886 */
Michal Vasko99b0aad2015-12-01 12:28:51 +0100887const struct lys_module *ly_ctx_load_module(struct ly_ctx *ctx, const char *name, const char *revision);
888
889/**
890 * @brief Callback for retrieving missing included or imported models in a custom way.
891 *
Michal Vasko84475152016-07-25 16:16:25 +0200892 * @param[in] mod_name Missing module name.
893 * @param[in] mod_rev Optional missing module revision.
894 * @param[in] submod_name Optional missing submodule name.
895 * @param[in] submod_rev Optional missing submodule revision.
Michal Vasko99b0aad2015-12-01 12:28:51 +0100896 * @param[in] user_data User-supplied callback data.
897 * @param[out] format Format of the returned module data.
Michal Vasko880dceb2016-03-03 15:44:56 +0100898 * @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 +0200899 * @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 +0100900 */
Michal Vasko84475152016-07-25 16:16:25 +0200901typedef char *(*ly_module_clb)(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev,
902 void *user_data, LYS_INFORMAT *format, void (**free_module_data)(void *model_data));
Michal Vasko99b0aad2015-12-01 12:28:51 +0100903
904/**
905 * @brief Set missing include or import model callback.
906 *
907 * @param[in] ctx Context that will use this callback.
908 * @param[in] clb Callback responsible for returning a missing model.
909 * @param[in] user_data Arbitrary data that will always be passed to the callback \p clb.
910 */
911void ly_ctx_set_module_clb(struct ly_ctx *ctx, ly_module_clb clb, void *user_data);
912
913/**
914 * @brief Get the custom callback for missing module retrieval.
915 *
916 * @param[in] ctx Context to read from.
917 * @param[in] user_data Optional pointer for getting the user-supplied callbck data.
918 * @return Custom user missing module callback or NULL if not set.
919 */
920ly_module_clb ly_ctx_get_module_clb(const struct ly_ctx *ctx, void **user_data);
Michal Vasko82465962015-11-10 11:03:11 +0100921
922/**
Radek Krejcifd4e6e32015-08-10 15:00:51 +0200923 * @brief Get pointer to the schema tree of the module of the specified namespace
924 *
925 * @param[in] ctx Context to work in.
926 * @param[in] ns Namespace of the YANG module to get.
927 * @param[in] revision Optional revision date of the YANG module to get. If not specified,
928 * the schema in the newest revision is returned if any.
929 * @return Pointer to the data model structure, NULL if no schema following the namespace and
930 * revision requirements is present in the context.
931 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100932const 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 +0200933
934/**
Radek Krejci62f0da72016-03-07 11:35:43 +0100935 * @brief Get submodule of a main module.
936 *
937 * 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 +0200938 *
Radek Krejcia7533f22016-03-07 07:37:45 +0100939 * @param[in] ctx Context to work in.
Michal Vaskof6d94c62016-04-05 11:21:54 +0200940 * @param[in] module Name of the main (belongs-to) module. If NULL, all module submodules are searched.
941 * @param[in] revision Optional revision date of \p module. If NULL, all revisions of \p module
942 * are searched. If set, \p module must also be set.
Radek Krejcia7533f22016-03-07 07:37:45 +0100943 * @param[in] submodule Name of the submodule to get.
Michal Vaskof6d94c62016-04-05 11:21:54 +0200944 * @param[in] sub_revision Optional revision date of \p submodule. If NULL, the newest revision of \p submodule
945 * is returned.
Michal Vasko7bf06882015-07-03 15:33:56 +0200946 * @return Pointer to the data model structure.
947 */
Radek Krejcia7533f22016-03-07 07:37:45 +0100948const 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 +0200949 const char *submodule, const char *sub_revision);
Michal Vasko7bf06882015-07-03 15:33:56 +0200950
951/**
Radek Krejci62f0da72016-03-07 11:35:43 +0100952 * @brief Get submodule of a main module.
953 *
954 * If you have only the name (and optionally revision) of the submodule's main module, use ly_ctx_get_submodule()
955 * instead.
956 *
957 * @param[in] main_module Main module (belongs to) of the searched submodule.
958 * @param[in] submodule Name of the submodule to get.
959 * @return Pointer to the data model structure.
960 */
961const struct lys_submodule *ly_ctx_get_submodule2(const struct lys_module *main_module, const char *submodule);
962
963/**
Michal Vasko3547c532016-03-14 09:40:50 +0100964 * @brief Get schema node according to the given schema node identifier in JSON format.
Michal Vasko3edeaf72016-02-11 13:17:43 +0100965 *
Michal Vasko3547c532016-03-14 09:40:50 +0100966 * If the \p nodeid is absolute, the first node identifier must be prefixed with
967 * the module name. Then every other identifier either has an explicit module name or
968 * the module name of the previous node is assumed. Examples:
Michal Vasko3edeaf72016-02-11 13:17:43 +0100969 *
970 * /ietf-netconf-monitoring:get-schema/input/identifier
971 * /ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address/ip
972 *
Michal Vasko3547c532016-03-14 09:40:50 +0100973 * If the \p nodeid is relative, \p start is mandatory and is the starting point
974 * for the resolution. The first node identifier does not need a module name.
975 *
Michal Vasko7b54f7e2016-05-03 15:07:31 +0200976 * Predicates on lists are accepted (ignored) in the form of "<key>(=<value>)"
977 * and on leaves/leaf-lists ".(=<value>)".
978 *
Michal Vasko3edeaf72016-02-11 13:17:43 +0100979 * @param[in] ctx Context to work in.
Michal Vasko3547c532016-03-14 09:40:50 +0100980 * @param[in] start Starting node for a relative schema node identifier, in which
981 * case it is mandatory.
982 * @param[in] nodeid JSON schema node identifier.
Michal Vasko3edeaf72016-02-11 13:17:43 +0100983 * @return Resolved schema node or NULL.
984 */
Michal Vasko3547c532016-03-14 09:40:50 +0100985const 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 +0100986
987/**
Radek Krejci3045cf32015-05-28 10:58:52 +0200988 * @brief Free all internal structures of the specified context.
989 *
990 * The function should be used before terminating the application to destroy
991 * and free all structures internally used by libyang. If the caller uses
992 * multiple contexts, the function should be called for each used context.
993 *
994 * All instance data are supposed to be freed before destroying the context.
995 * Data models are destroyed automatically as part of ly_ctx_destroy() call.
996 *
997 * @param[in] ctx libyang context to destroy
Radek Krejcifa0b5e02016-02-04 13:57:03 +0100998 * @param[in] private_destructor Optional destructor function for private objects assigned
999 * to the nodes via lys_set_private(). If NULL, the private objects are not freed by libyang.
Radek Krejcida04f4a2015-05-21 12:54:09 +02001000 */
Radek Krejcifa0b5e02016-02-04 13:57:03 +01001001void ly_ctx_destroy(struct ly_ctx *ctx, void (*private_destructor)(const struct lys_node *node, void *priv));
Radek Krejcida04f4a2015-05-21 12:54:09 +02001002
Radek Krejci26715a42015-07-29 14:10:45 +02001003/**@} context */
1004
1005/**
Radek Krejcidef50022016-02-01 16:38:32 +01001006 * @defgroup nodeset Tree nodes set
Radek Krejcidc154432016-01-21 11:10:59 +01001007 * @ingroup datatree
1008 * @ingroup schematree
1009 * @{
1010 *
Radek Krejcidef50022016-02-01 16:38:32 +01001011 * Structure and functions to hold and manipulate with sets of nodes from schema or data trees.
1012 */
1013
1014/**
Radek Krejci8f08df12016-03-21 11:11:30 +01001015 * @brief set array of ::ly_set
1016 * It is kept in union to keep ::ly_set generic for data as well as schema trees
1017 */
1018union ly_set_set {
1019 struct lys_node **s; /**< array of pointers to a ::lys_node objects */
1020 struct lyd_node **d; /**< array of pointers to a ::lyd_node objects */
1021 void **g; /**< dummy array for generic work */
1022};
1023
1024/**
Radek Krejcidc154432016-01-21 11:10:59 +01001025 * @brief Structure to hold a set of (not necessary somehow connected) ::lyd_node or ::lys_node objects.
1026 * Caller is supposed to not mix the type of objects added to the set and according to its knowledge about
1027 * the set content, it is supposed to access the set via the sset, dset or set members of the structure.
1028 *
Radek Krejci09891a22016-06-10 10:59:22 +02001029 * Until ly_set_rm() or ly_set_rm_index() is used, the set keeps the order of the inserted items as they
1030 * were added into the set, so the first added item is on array index 0.
1031 *
Radek Krejcidef50022016-02-01 16:38:32 +01001032 * To free the structure, use ly_set_free() function, to manipulate with the structure, use other
1033 * ly_set_* functions.
Radek Krejcidc154432016-01-21 11:10:59 +01001034 */
1035struct ly_set {
1036 unsigned int size; /**< allocated size of the set array */
1037 unsigned int number; /**< number of elements in (used size of) the set array */
Radek Krejci8f08df12016-03-21 11:11:30 +01001038 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 +01001039};
1040
1041/**
Radek Krejci09891a22016-06-10 10:59:22 +02001042 * @brief Option for ly_set_add() to allow duplicities in the ly_set structure so the
1043 * set is not used as a set, but as a list of (container for) items.
1044 */
1045#define LY_SET_OPT_USEASLIST 0x01
1046
1047/**
Radek Krejcidef50022016-02-01 16:38:32 +01001048 * @brief Create and initiate new ::ly_set structure.
Radek Krejcidc154432016-01-21 11:10:59 +01001049 *
Radek Krejcidef50022016-02-01 16:38:32 +01001050 * @return Created ::ly_set structure or NULL in case of error.
Radek Krejcidc154432016-01-21 11:10:59 +01001051 */
1052struct ly_set *ly_set_new(void);
1053
1054/**
Radek Krejcie8c1b572016-07-26 15:09:52 +02001055 * @brief Duplicate the existing set.
1056 *
1057 * @param[in] set Original set to duplicate
1058 * @return Duplication of the original set.
1059 */
1060struct ly_set *ly_set_dup(const struct ly_set *set);
1061
1062/**
Radek Krejcidc154432016-01-21 11:10:59 +01001063 * @brief Add a ::lyd_node or ::lys_node object into the set
1064 *
Radek Krejci29cb50d2016-05-09 16:31:13 +02001065 * Since it is a set, the function checks for duplicity and if the
1066 * node is already in the set, the index of the previously added
1067 * node is returned.
1068 *
Radek Krejcidc154432016-01-21 11:10:59 +01001069 * @param[in] set Set where the \p node will be added.
1070 * @param[in] node The ::lyd_node or ::lys_node object to be added into the \p set;
Radek Krejci09891a22016-06-10 10:59:22 +02001071 * @param[in] options Options to change behavior of the function. Accepted options are:
1072 * - #LY_SET_OPT_USEASLIST - do not check for duplicities
Radek Krejci29cb50d2016-05-09 16:31:13 +02001073 * @return -1 on failure, index of the \p node in the set on success
Radek Krejcidc154432016-01-21 11:10:59 +01001074 */
Radek Krejci09891a22016-06-10 10:59:22 +02001075int ly_set_add(struct ly_set *set, void *node, int options);
Radek Krejcidc154432016-01-21 11:10:59 +01001076
1077/**
Radek Krejci29ed4082016-05-09 14:25:56 +02001078 * @brief Remove all objects from the set, but keep the set container for further use.
1079 *
1080 * @param[in] set Set to clean.
1081 * @return 0 on success
1082 */
1083int ly_set_clean(struct ly_set *set);
1084
1085/**
Radek Krejcidc154432016-01-21 11:10:59 +01001086 * @brief Remove a ::lyd_node or ::lys_node object from the set.
1087 *
1088 * Note that after removing a node from a set, indexes of other nodes in the set can change
1089 * (the last object is placed instead of the removed object).
1090 *
1091 * @param[in] set Set from which the \p node will be removed.
1092 * @param[in] node The ::lyd_node or ::lys_node object to be removed from the \p set;
1093 * @return 0 on success
1094 */
1095int ly_set_rm(struct ly_set *set, void *node);
1096
1097/**
1098 * @brief Remove a ::lyd_node or ::lys_node object from the set index.
1099 *
1100 * Note that after removing a node from a set, indexes of other nodes in the set can change
1101 * (the last object is placed instead of the removed object).
1102 *
1103 * @param[in] set Set from which a node will be removed.
1104 * @param[in] index Index of the ::lyd_node or ::lys_node object in the \p set to be removed from the \p set;
1105 * @return 0 on success
1106 */
1107int ly_set_rm_index(struct ly_set *set, unsigned int index);
1108
1109/**
Radek Krejcidef50022016-02-01 16:38:32 +01001110 * @brief Free the ::ly_set data. Frees only the set structure content, not the referred data.
Radek Krejcidc154432016-01-21 11:10:59 +01001111 *
1112 * @param[in] set The set to be freed.
1113 */
1114void ly_set_free(struct ly_set *set);
1115
Radek Krejcidef50022016-02-01 16:38:32 +01001116/**@} nodeset */
Radek Krejci6140e4e2015-10-09 15:50:55 +02001117
1118/**
Radek Krejci5044be32016-01-18 17:05:51 +01001119 * @defgroup printerflags Printer flags
Radek Krejcidef50022016-02-01 16:38:32 +01001120 * @ingroup datatree
Radek Krejci5044be32016-01-18 17:05:51 +01001121 *
1122 * Validity flags for data nodes.
1123 *
1124 * @{
1125 */
Radek Krejci2537fd32016-09-07 16:22:41 +02001126#define LYP_WITHSIBLINGS 0x01 /**< Flag for printing also the (following) sibling nodes of the data node. */
1127#define LYP_FORMAT 0x02 /**< Flag for formatted output. */
1128#define LYP_KEEPEMPTYCONT 0x04 /**< Preserve empty non-presence containers */
1129#define LYP_WD_MASK 0xF0 /**< Mask for with-defaults modes */
1130#define LYP_WD_EXPLICIT 0x00 /**< Explicit mode - print only data explicitly being present in the data tree.
1131 Note that this is the default value when no WD option is specified. */
1132#define LYP_WD_TRIM 0x10 /**< Do not print the nodes with the value equal to their default value */
1133#define LYP_WD_ALL 0x20 /**< Include implicit default nodes */
1134#define LYP_WD_ALL_TAG 0x40 /**< Same as #LYP_WD_ALL but also adds attribute 'default' with value 'true' to
1135 all nodes that has its default value. The 'default' attribute has namespace:
1136 urn:ietf:params:xml:ns:netconf:default:1.0 and thus the attributes are
1137 printed only when the ietf-netconf-with-defaults module is present in libyang
1138 context. */
1139#define LYP_WD_IMPL_TAG 0x80 /**< Same as LYP_WD_ALL_TAG but the attributes are added only to the nodes that
1140 are not explicitly present in the original data tree despite their
1141 value is equal to their default value. There is the same limitation regarding
1142 the presence of ietf-netconf-with-defaults module in libyang context. */
Radek Krejci5044be32016-01-18 17:05:51 +01001143
1144/**
1145 * @}
1146 */
1147
1148/**
Radek Krejci3045cf32015-05-28 10:58:52 +02001149 * @defgroup logger Logger
1150 * @{
1151 *
1152 * Publicly visible functions and values of the libyang logger. For more
1153 * information, see \ref howtologger.
1154 */
1155
1156/**
1157 * @typedef LY_LOG_LEVEL
1158 * @brief Verbosity levels of the libyang logger.
1159 */
1160typedef enum {
Michal Vasko8f7e8d92016-07-01 11:33:58 +02001161 LY_LLSILENT = -1, /**< Print no messages. */
1162 LY_LLERR = 0, /**< Print only error messages, default value. */
1163 LY_LLWRN, /**< Print error and warning messages. */
1164 LY_LLVRB, /**< Besides errors and warnings, print some other verbose messages. */
1165 LY_LLDBG /**< Print all messages including some development debug messages. */
Radek Krejci3045cf32015-05-28 10:58:52 +02001166} LY_LOG_LEVEL;
1167
1168/**
1169 * @brief Set logger verbosity level.
1170 * @param[in] level Verbosity level.
1171 */
1172void ly_verb(LY_LOG_LEVEL level);
1173
1174/**
Michal Vaskof1d62cf2015-12-07 13:17:11 +01001175 * @brief Set logger callback.
Michal Vasko13661142016-04-11 10:53:53 +02001176 *
1177 * !IMPORTANT! If an error has a specific error-app-tag defined in the model, it will NOT be set
1178 * at the time of calling this callback. It will be set right after, so to retrieve it
1179 * it must be checked afterwards with ly_errapptag().
1180 *
Michal Vaskof1d62cf2015-12-07 13:17:11 +01001181 * @param[in] clb Logging callback.
Radek Krejciadb57612016-02-16 13:34:34 +01001182 * @param[in] path flag to resolve and provide path as the third parameter of the callback function. In case of
1183 * validation and some other errors, it can be useful to get the path to the problematic element. Note,
1184 * that according to the tree type and the specific situation, the path can slightly differs (keys
1185 * presence) or it can be NULL, so consider it as an optional parameter. If the flag is 0, libyang will
1186 * not bother with resolving the path.
Michal Vaskof1d62cf2015-12-07 13:17:11 +01001187 */
Radek Krejciadb57612016-02-16 13:34:34 +01001188void 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 +01001189
1190/**
1191 * @brief Get logger callback.
1192 * @return Logger callback (can be NULL).
1193 */
Radek Krejciadb57612016-02-16 13:34:34 +01001194void (*ly_get_log_clb(void))(LY_LOG_LEVEL, const char *, const char *);
Michal Vaskof1d62cf2015-12-07 13:17:11 +01001195
1196/**
Radek Krejci3045cf32015-05-28 10:58:52 +02001197 * @typedef LY_ERR
Radek Krejci26715a42015-07-29 14:10:45 +02001198 * @brief libyang's error codes available via ly_errno extern variable.
Radek Krejci9b4ca392015-04-10 08:31:27 +02001199 * @ingroup logger
1200 */
1201typedef enum {
Radek Krejciae6817a2015-08-10 14:02:06 +02001202 LY_SUCCESS, /**< no error, not set by functions, included just to complete #LY_ERR enumeration */
Radek Krejci6e4ffbb2015-06-16 10:34:41 +02001203 LY_EMEM, /**< Memory allocation failure */
1204 LY_ESYS, /**< System call failure */
1205 LY_EINVAL, /**< Invalid value */
1206 LY_EINT, /**< Internal error */
1207 LY_EVALID /**< Validation failure */
Radek Krejci3045cf32015-05-28 10:58:52 +02001208} LY_ERR;
Radek Krejci7d9f46a2016-01-29 13:53:18 +01001209
Radek Krejci26715a42015-07-29 14:10:45 +02001210/**
Michal Vaskof5035ce2016-03-11 10:21:31 +01001211 * @typedef LY_VECODE
1212 * @brief libyang's codes of validation error. Whenever ly_errno is set to LY_EVALID, the ly_vecode is also set
1213 * to the appropriate LY_VECODE value.
Radek Krejcia37b39c2016-03-09 16:38:18 +01001214 * @ingroup logger
1215 */
1216typedef enum {
Michal Vaskof5035ce2016-03-11 10:21:31 +01001217 LYVE_SUCCESS = 0, /**< no error */
Radek Krejcia37b39c2016-03-09 16:38:18 +01001218
Michal Vaskof5035ce2016-03-11 10:21:31 +01001219 LYVE_XML_MISS, /**< missing XML object */
1220 LYVE_XML_INVAL, /**< invalid XML object */
1221 LYVE_XML_INCHAR, /**< invalid XML character */
Radek Krejcia37b39c2016-03-09 16:38:18 +01001222
Michal Vaskof5035ce2016-03-11 10:21:31 +01001223 LYVE_EOF, /**< unexpected end of input data */
1224 LYVE_INSTMT, /**< invalid statement (schema) */
1225 /* */
Michal Vaskoca7cbc42016-07-01 11:36:53 +02001226 LYVE_INPAR, /**< invalid (in)direct parent (schema) */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001227 LYVE_INID, /**< invalid identifier (schema) */
1228 LYVE_INDATE, /**< invalid date format */
1229 LYVE_INARG, /**< invalid value of a statement argument (schema) */
1230 LYVE_MISSSTMT, /**< missing required statement (schema) */
1231 /* */
1232 LYVE_MISSARG, /**< missing required statement argument (schema) */
1233 LYVE_TOOMANY, /**< too many instances of some object */
1234 LYVE_DUPID, /**< duplicated identifier (schema) */
1235 LYVE_DUPLEAFLIST, /**< multiple instances of leaf-list */
1236 LYVE_DUPLIST, /**< multiple instances of list */
Michal Vaskoa540df22016-04-11 16:14:35 +02001237 LYVE_NOUNIQ, /**< unique leaves match on 2 list instances (data) */
Radek Krejcie663e012016-08-01 17:12:34 +02001238 LYVE_ENUM_INVAL, /**< invalid enum value (schema) */
1239 LYVE_ENUM_INNAME, /**< invalid enum name (schema) */
1240 /* */
1241 /* */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001242 LYVE_ENUM_WS, /**< enum name with leading/trailing whitespaces (schema) */
Radek Krejcie663e012016-08-01 17:12:34 +02001243 LYVE_BITS_INVAL, /**< invalid bits value (schema) */
1244 LYVE_BITS_INNAME, /**< invalid bits name (schema) */
1245 /* */
1246 /* */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001247 LYVE_INMOD, /**< invalid module name */
1248 /* */
1249 LYVE_KEY_NLEAF, /**< list key is not a leaf (schema) */
1250 LYVE_KEY_TYPE, /**< invalid list key type (schema) */
1251 LYVE_KEY_CONFIG, /**< key config value differs from the list config value */
1252 LYVE_KEY_MISS, /**< list key not found (schema) */
1253 LYVE_KEY_DUP, /**< duplicated key identifier (schema) */
1254 LYVE_INREGEX, /**< invalid regular expression (schema) */
1255 LYVE_INRESOLV, /**< no resolvents found (schema) */
1256 LYVE_INSTATUS, /**< invalid derivation because of status (schema) */
Radek Krejcid8fb03c2016-06-13 15:52:22 +02001257 LYVE_CIRC_LEAFREFS,/**< circular chain of leafrefs detected (schema) */
Radek Krejcie8c1b572016-07-26 15:09:52 +02001258 LYVE_CIRC_FEATURES,/**< circular chain of features detected (schema) */
Radek Krejci151b8cc2016-06-22 10:14:21 +02001259 LYVE_CIRC_IMPORTS, /**< circular chain of imports detected (schema) */
1260 LYVE_CIRC_INCLUDES,/**< circular chain of includes detected (schema) */
Michal Vasko88de3e42016-06-29 11:05:32 +02001261 LYVE_INVER, /**< non-matching YANG versions of module and its submodules (schema) */
Radek Krejcia37b39c2016-03-09 16:38:18 +01001262
Michal Vaskof5035ce2016-03-11 10:21:31 +01001263 LYVE_OBSDATA, /**< obsolete data instantiation (data) */
1264 /* */
1265 LYVE_NORESOLV, /**< no resolvents found for an expression (data) */
1266 LYVE_INELEM, /**< invalid element (data) */
1267 /* */
1268 LYVE_MISSELEM, /**< missing required element (data) */
1269 LYVE_INVAL, /**< invalid value of an element (data) */
Radek Krejci9bfcbde2016-04-07 16:30:15 +02001270 LYVE_INVALATTR, /**< invalid attribute value (data) */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001271 LYVE_INATTR, /**< invalid attribute in an element (data) */
1272 LYVE_MISSATTR, /**< missing attribute in an element (data) */
Michal Vasko6ac68282016-04-11 10:56:47 +02001273 LYVE_NOCONSTR, /**< value out of range/length/pattern (data) */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001274 LYVE_INCHAR, /**< unexpected characters (data) */
1275 LYVE_INPRED, /**< predicate resolution fail (data) */
1276 LYVE_MCASEDATA, /**< data for more cases of a choice (data) */
Michal Vasko6ac68282016-04-11 10:56:47 +02001277 LYVE_NOMUST, /**< unsatisfied must condition (data) */
1278 LYVE_NOWHEN, /**< unsatisfied when condition (data) */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001279 LYVE_INORDER, /**< invalid order of elements (data) */
Radek Krejci03b71f72016-03-16 11:10:09 +01001280 LYVE_INWHEN, /**< irresolvable when condition (data) */
Michal Vasko6ac68282016-04-11 10:56:47 +02001281 LYVE_NOMIN, /**< min-elements constraint not honored (data) */
1282 LYVE_NOMAX, /**< max-elements constraint not honored (data) */
1283 LYVE_NOREQINS, /**< required instance does not exits (data) */
1284 LYVE_NOLEAFREF, /**< leaf pointed to by leafref does not exist (data) */
1285 LYVE_NOMANDCHOICE, /**< no mandatory choice case branch exists (data) */
Radek Krejcia37b39c2016-03-09 16:38:18 +01001286
Michal Vasko5b3492c2016-07-20 09:37:40 +02001287 LYVE_XPATH_INSNODE,/**< schema node not found */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001288 LYVE_XPATH_INTOK, /**< unexpected XPath token */
1289 LYVE_XPATH_EOF, /**< unexpected end of an XPath expression */
1290 LYVE_XPATH_INOP, /**< invalid XPath operation operands */
1291 /* */
1292 LYVE_XPATH_INCTX, /**< invalid XPath context type */
1293 LYVE_XPATH_INARGCOUNT, /**< invalid number of arguments for an XPath function */
Michal Vasko6fae1362016-03-11 15:10:00 +01001294 LYVE_XPATH_INARGTYPE, /**< invalid type of arguments for an XPath function */
Michal Vasko11f8da72016-08-24 15:54:57 +02001295 LYVE_XPATH_DUMMY, /**< invaid use of the XPath dummy node */
Michal Vasko6fae1362016-03-11 15:10:00 +01001296
1297 LYVE_PATH_INCHAR, /**< invalid characters (path) */
Michal Vaskoe733d682016-03-14 09:08:27 +01001298 LYVE_PATH_INMOD, /**< invalid module name (path) */
1299 LYVE_PATH_MISSMOD, /**< missing module name (path) */
Michal Vasko6fae1362016-03-11 15:10:00 +01001300 LYVE_PATH_INNODE, /**< invalid node name (path) */
Michal Vasko6fae1362016-03-11 15:10:00 +01001301 LYVE_PATH_INKEY, /**< invalid key name (path) */
1302 LYVE_PATH_MISSKEY, /**< missing some list keys (path) */
1303 LYVE_PATH_EXISTS, /**< target node already exists (path) */
1304 LYVE_PATH_MISSPAR, /**< some parent of the target node is missing (path) */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001305} LY_VECODE;
Radek Krejcia37b39c2016-03-09 16:38:18 +01001306
1307/**
Radek Krejci7d9f46a2016-01-29 13:53:18 +01001308 * @cond INTERNAL
Radek Krejci386714d2016-02-15 10:24:30 +01001309 * Get address of (thread-specific) `ly_errno' variable.
Radek Krejci26715a42015-07-29 14:10:45 +02001310 */
Radek Krejci7d9f46a2016-01-29 13:53:18 +01001311LY_ERR *ly_errno_location(void);
1312
Michal Vaskof5035ce2016-03-11 10:21:31 +01001313LY_VECODE *ly_vecode_location(void);
Radek Krejcia37b39c2016-03-09 16:38:18 +01001314
Radek Krejci7d9f46a2016-01-29 13:53:18 +01001315/**
1316 * @endcond INTERNAL
Radek Krejcidef50022016-02-01 16:38:32 +01001317 * @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 +01001318 */
1319#define ly_errno (*ly_errno_location())
Radek Krejci9b4ca392015-04-10 08:31:27 +02001320
Radek Krejci386714d2016-02-15 10:24:30 +01001321/**
Radek Krejcia37b39c2016-03-09 16:38:18 +01001322 * @brief libyang's validation error code
1323 */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001324#define ly_vecode (*ly_vecode_location())
Radek Krejcia37b39c2016-03-09 16:38:18 +01001325
1326/**
Michal Vasko13661142016-04-11 10:53:53 +02001327 * @brief Get the last (thread-specific) error message. If the coresponding module defined
1328 * a specific error message, it will be used instead the default one.
Radek Krejci6e8fc0b2016-02-16 14:33:37 +01001329 *
1330 * Sometimes, the error message is extended with path of the element where is the problem.
1331 * The path is available via ly_errpath().
1332 *
Radek Krejcib50551c2016-04-19 09:15:38 +02001333 * @return Text of the last error message, empty string if there is no error.
Radek Krejci386714d2016-02-15 10:24:30 +01001334 */
1335const char *ly_errmsg(void);
1336
Radek Krejci6e8fc0b2016-02-16 14:33:37 +01001337/**
1338 * @brief Get the last (thread-specific) path of the element where was an error.
1339 *
1340 * The path always corresponds to the error message available via ly_errmsg(), so
1341 * whenever a subsequent error message is printed, the path is erased or rewritten.
Radek Krejci3cc10962016-04-13 15:03:27 +02001342 * The path reflects the type of the processed tree - data path for data tree functions
1343 * and schema path in case of schema tree functions. In case of processing YIN schema
1344 * or XML data, the path can be just XML path. In such a case, the corresponding
1345 * ly_vecode (value 1-3) is set.
Radek Krejci6e8fc0b2016-02-16 14:33:37 +01001346 *
Radek Krejcib50551c2016-04-19 09:15:38 +02001347 * @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 +01001348 */
1349const char *ly_errpath(void);
1350
Michal Vasko13661142016-04-11 10:53:53 +02001351/**
1352 * @brief Get the last (thread-specific) error-app-tag if there was a specific one defined
1353 * in the module for the last error.
1354 *
1355 * The app-tag always corresponds to the error message available via ly_errmsg(), so
1356 * whenever a subsequent error message is printed, the app-tag is erased or rewritten.
1357 *
Radek Krejcib50551c2016-04-19 09:15:38 +02001358 * @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 +02001359 */
1360const char *ly_errapptag(void);
1361
Radek Krejci3045cf32015-05-28 10:58:52 +02001362/**@} logger */
Radek Krejci9b4ca392015-04-10 08:31:27 +02001363
Radek Krejci39d8d0d2015-08-17 13:42:45 +02001364#ifdef __cplusplus
1365}
1366#endif
1367
Radek Krejci9b4ca392015-04-10 08:31:27 +02001368#endif /* LY_LIBYANG_H_ */