blob: 21d6599b6cd5f7a9d80a63c83fb651238aa1c9cb [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 *
37 * - Parsing (and validating) schemas in YIN format.
38 * - Parsing, validating and printing instance data in XML format.
39 * - Parsing, validating and printing instance data in JSON format.
40 * - Manipulation with the instance data.
41 *
42 * - \todo Parsing (and validating) schemas in YANG format.
43 *
44 * @subsection about-features-others Extra (side-effect) Features
45 *
46 * - XML parser.
47 * - Optimized string storage (dictionary).
48 *
49 * @section about-license License
50 *
51 * Copyright (c) 2015-2016 CESNET, z.s.p.o.
52 *
53 * (The BSD 3-Clause License)
54 *
55 * Redistribution and use in source and binary forms, with or without
56 * modification, are permitted provided that the following conditions
57 * are met:
58 * 1. Redistributions of source code must retain the above copyright
59 * notice, this list of conditions and the following disclaimer.
60 * 2. Redistributions in binary form must reproduce the above copyright
61 * notice, this list of conditions and the following disclaimer in
62 * the documentation and/or other materials provided with the
63 * distribution.
64 * 3. Neither the name of the Company nor the names of its contributors
65 * may be used to endorse or promote products derived from this
66 * software without specific prior written permission.
67 */
68
69/**
Radek Krejci26715a42015-07-29 14:10:45 +020070 * @page howto How To ...
71 *
72 * - @subpage howtocontext
Radek Krejcid9ba3e32015-07-30 15:08:18 +020073 * - @subpage howtoschemas
74 * - @subpage howtodata
Michal Vasko0f14ba62016-03-21 15:38:11 +010075 * - @subpage howtoxpath
Radek Krejcidef50022016-02-01 16:38:32 +010076 * - @subpage howtoxml
77 * - @subpage howtothreads
Radek Krejci26715a42015-07-29 14:10:45 +020078 * - @subpage howtologger
79 */
Radek Krejcida04f4a2015-05-21 12:54:09 +020080
Radek Krejci26715a42015-07-29 14:10:45 +020081/** @page howtocontext Context
82 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +020083 * The context concept allows callers to work in environments with different sets of YANG schemas.
Radek Krejci26715a42015-07-29 14:10:45 +020084 *
85 * The first step in libyang is to create a new context using ly_ctx_new(). It returns a handler
86 * used in the following work.
87 *
88 * When creating a new context, search dir can be specified (NULL is accepted) to provide directory
89 * where libyang will automatically search for schemas being imported or included. The search path
90 * can be later changed via ly_ctx_set_searchdir() function. Before exploring the specified search
91 * dir, libyang tries to get imported and included schemas from the current working directory first.
Radek Krejcidef50022016-02-01 16:38:32 +010092 * This automatic searching can be completely avoided when the caller sets module searching callback
93 * (#ly_module_clb) via ly_ctx_set_module_clb().
Radek Krejci26715a42015-07-29 14:10:45 +020094 *
Radek Krejcidef50022016-02-01 16:38:32 +010095 * Schemas are added into the context using [parser functions](@ref howtoschemasparsers) - \b lys_parse_*() or \b lyd_parse_*().
96 * In case of schemas, also ly_ctx_load_module() can be used - in that case the #ly_module_clb or automatic
97 * search in working directory and in the searchpath is used. Note, that functions for schemas have \b lys_
98 * prefix while functions for instance data have \b lyd_ prefix.
Radek Krejcid9ba3e32015-07-30 15:08:18 +020099 *
Radek Krejcif647e612015-07-30 11:36:07 +0200100 * Context can hold multiple revisons of the same schema.
Radek Krejci26715a42015-07-29 14:10:45 +0200101 *
Michal Vasko462be9a2016-04-05 11:24:08 +0200102 * Context holds all modules and their submodules internally. To get a specific module or submodule, use
103 * ly_ctx_get_module() and ly_ctx_get_submodule(). If you need to do something with all the modules or
104 * submodules in the context, it is advised to iterate over them using ly_ctx_get_module_iter(), it is
105 * the most efficient way. Alternatively, the ly_ctx_info() function can be used to get complex information
106 * about the schemas in the context in the form of data tree defined by
Radek Krejcibd9e8d22016-02-03 14:11:48 +0100107 * <a href="https://tools.ietf.org/html/draft-ietf-netconf-yang-library-04">ietf-yang-library</a> schema.
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200108 *
109 * Modules held by a context cannot be removed one after one. The only way how to \em change modules in the
110 * context is to create a new context and remove the old one. To remove a context, there is ly_ctx_destroy()
111 * function.
112 *
Radek Krejcidef50022016-02-01 16:38:32 +0100113 * - @subpage howtocontextdict
114 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200115 * \note API for this group of functions is available in the [context module](@ref context).
116 *
Radek Krejcidef50022016-02-01 16:38:32 +0100117 * Functions List
118 * --------------
119 * - ly_ctx_new()
120 * - ly_ctx_set_searchdir()
121 * - ly_ctx_get_searchdir()
122 * - ly_ctx_set_module_clb()
123 * - ly_ctx_get_module_clb()
124 * - ly_ctx_load_module()
125 * - ly_ctx_info()
Michal Vaskod7957c02016-04-01 10:27:26 +0200126 * - ly_ctx_get_module_iter()
Radek Krejcidef50022016-02-01 16:38:32 +0100127 * - ly_ctx_get_module()
128 * - ly_ctx_get_module_by_ns()
Radek Krejcidef50022016-02-01 16:38:32 +0100129 * - ly_ctx_get_submodule()
Michal Vasko3edeaf72016-02-11 13:17:43 +0100130 * - ly_ctx_get_node()
Radek Krejcidef50022016-02-01 16:38:32 +0100131 * - ly_ctx_destroy()
132 */
133
134/**
135 * @page howtocontextdict Context Dictionary
136 *
137 * Context includes dictionary to store strings more effectively. The most of strings repeats quite often in schema
138 * as well as data trees. Therefore, instead of allocating those strings each time they appear, libyang stores them
139 * as records in the dictionary. The basic API to the context dictionary is public, so even a caller application can
140 * use the dictionary.
141 *
142 * To insert a string into the dictionary, caller can use lydict_insert() (adding a constant string) or
143 * lydict_insert_zc() (for dynamically allocated strings that won't be used by the caller after its insertion into
144 * the dictionary). Both functions return the pointer to the inserted string in the dictionary record.
145 *
146 * To remove (reference of the) string from the context dictionary, lydict_remove() is supposed to be used.
147 *
148 * \note Incorrect usage of the dictionary can break libyang functionality.
149 *
150 * \note API for this group of functions is described in the [XML Parser module](@ref dict).
151 *
152 * Functions List
153 * --------------
154 * - lydict_insert()
155 * - lydict_insert_zc()
156 * - lydict_remove()
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200157 */
158
159/**
160 * @page howtoschemas Schemas
161 *
Radek Krejcidef50022016-02-01 16:38:32 +0100162 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200163 * Schema is an internal libyang's representation of a YANG data model. Each schema is connected with
Radek Krejcidef50022016-02-01 16:38:32 +0100164 * its [context](@ref howtocontext) and loaded using [parser functions](@ref howtoschemasparsers). It means, that
165 * the schema cannot be created (nor changed) programmatically. In libyang, schemas are used only to
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200166 * access data model definitions.
167 *
Radek Krejcidef50022016-02-01 16:38:32 +0100168 * Schema tree nodes are able to hold private objects (via a pointer to a structure, function, variable, ...) used by
169 * a caller application. Such an object can be assigned to a specific node using lys_set_private() function.
170 * Note that the object is not freed by libyang when the context is being destroyed. So the caller is responsible
171 * for freeing the provided structure after the context is destroyed or the private pointer is set to NULL in
172 * appropriate schema nodes where the object was previously set. On the other hand, freeing the object while the schema
173 * tree is still used can lead to a segmentation fault.
174 *
175 * - @subpage howtoschemasparsers
176 * - @subpage howtoschemasfeatures
177 * - @subpage howtoschemasprinters
178 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200179 * \note There are many functions to access information from the schema trees. Details are available in
180 * the [Schema Tree module](@ref schematree).
181 *
Radek Krejcidef50022016-02-01 16:38:32 +0100182 * Functions List (not assigned to above subsections)
183 * --------------------------------------------------
Radek Krejcidef50022016-02-01 16:38:32 +0100184 * - lys_get_next()
185 * - lys_parent()
186 * - lys_set_private()
187 */
188
189/**
190 * @page howtoschemasparsers Parsing Schemas
191 *
192 * Schema parser allows to read schema from a specific format. libyang supports the following schema formats:
193 *
194 * - YANG
195 *
196 * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020).
197 * Currently, only YANG 1.0 is supported.
198 *
199 * \todo YANG input is not yet implemented
200 *
201 * - YIN
202 *
203 * Alternative XML-based format to YANG. The details can be found in
204 * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11).
205 *
206 * When the [context](@ref howtocontext) is created, it already contains the following three schemas, which
207 * are implemented internally by libyang: *
208 * - ietf-inet-types@2013-07-15
209 * - ietf-yang-types@2013-07-15
210 * - ietf-yang-library@2015-07-03
211 *
212 * Other schemas can be added to the context manually as described in [context page](@ref howtocontext) by the functions
213 * listed below. Besides the schema parser functions, it is also possible to use ly_ctx_load_module() which tries to
214 * find the required schema automatically - using #ly_module_clb or automatic search in working directory and in the
215 * context's searchpath.
216 *
217 * Functions List
218 * --------------
Radek Krejci722b0072016-02-01 17:09:45 +0100219 * - lys_parse_mem()
Radek Krejcidef50022016-02-01 16:38:32 +0100220 * - lys_parse_fd()
221 * - lys_parse_path()
222 * - ly_ctx_set_module_clb()
223 * - ly_ctx_load_module()
224 */
225
226/**
227 * @page howtoschemasfeatures YANG Features Manipulation
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200228 *
229 * The group of functions prefixed by \b lys_features_ are used to access and manipulate with the schema's
230 * features.
231 *
232 * The first two functions are used to access information about the features in the schema.
233 * lys_features_list() provides list of all features defined in the specific schema and its
234 * submodules. Optionally, it can also provides information about the state of all features.
235 * Alternatively, caller can use lys_features_state() function to get state of one specific
236 * feature.
237 *
238 * The remaining two functions, lys_features_enable() and lys_features_disable(), are used
Radek Krejcidef50022016-02-01 16:38:32 +0100239 * to enable and disable the specific feature (or all via \b "*"). By default, when the module
240 * is loaded by libyang parser, all features are disabled.
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200241 *
Radek Krejcidef50022016-02-01 16:38:32 +0100242 * 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 +0200243 *
Radek Krejcidef50022016-02-01 16:38:32 +0100244 * Note, that the feature's state can affect some of the output formats (e.g. Tree format).
245 *
246 * Functions List
247 * --------------
248 * - lys_features_list()
249 * - lys_features_enable()
250 * - lys_features_disable()
251 * - lys_features_state()
252 * - lys_is_disabled()
253 */
254
255/**
256 * @page howtoschemasprinters Printing Schemas
257 *
258 * Schema printers allows to serialize internal representation of a schema module in a specific format. libyang
259 * supports the following schema formats for printing:
260 *
261 * - YANG
262 *
263 * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020).
264 * Currently, only YANG 1.0 is supported.
265 *
266 * - YIN
267 *
268 * Alternative XML-based format to YANG. The details can be found in
269 * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11).
270 *
Radek Krejcidef50022016-02-01 16:38:32 +0100271 * - Tree
272 *
273 * Simple tree structure of the module.
274 *
275 * - Info
276 *
277 * Detailed information about the specific node in the schema tree.
278 * It allows to print information not only about a specific module, but also about its specific part:
279 *
280 * - absolute-schema-nodeid
281 *
282 * e.g. \a `/modules/module-set-id` in \a `ietf-yang-library` module
283 *
284 * - <b>typedef/</b>typedef-name
285 *
286 * e.g. \a `typedef/revision-identifier` in \a `ietf-yang-library` module
287 *
288 * - <b>feature/</b>feature-name
289 *
290 * e.g. \a `feature/ssh` in \a `ietf-netconf-server` module
291 *
292 * - <b>grouping/</b>grouping-name/descendant-schema-nodeid
293 *
294 * e.g. \a `grouping/module` or \a `grouping/module/module/submodules` in \a `ietf-yang-library` module
295 *
296 * - <b>type/</b>leaf-or-leaflist
297 *
298 * e.g. \a `type/modules/module-set-id` in \a `ietf-yang-library` module
299 *
300 * Printer functions allow to print to the different outputs including a callback function which allows caller
301 * to have a full control of the output data - libyang passes to the callback a private argument (some internal
302 * data provided by a caller of lys_print_clb()), string buffer and number of characters to print. Note that the
303 * callback is supposed to be called multiple times during the lys_print_clb() execution.
304 *
305 * Functions List
306 * --------------
307 * - lys_print_mem()
308 * - lys_print_fd()
309 * - lys_print_file()
310 * - lys_print_clb()
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200311 */
312
313/**
314 * @page howtodata Data Instances
Radek Krejci26715a42015-07-29 14:10:45 +0200315 *
Radek Krejcidef50022016-02-01 16:38:32 +0100316 * All data nodes in data trees are connected with their schema node - libyang is not able to represent data of an
317 * unknown schema.
318 *
319 * By default, the represented data are supposed to represent a full YANG datastore content. So if a schema declares
320 * some mandatory nodes, despite configuration or status, the data are supposed to be present in the data tree being
321 * loaded or validated. However, it is possible to specify other kinds of data (see @ref parseroptions) allowing some
322 * exceptions to the validation process.
323 *
324 * Data validation is performed implicitly to the input data processed by the parser (\b lyd_parse_*() functions) and
325 * on demand via the lyd_validate() function. The lyd_validate() is supposed to be used when a (complex or simple)
326 * change is done on the data tree (via a combination of \b lyd_change_*(), \b lyd_insert*(), \b lyd_new*(),
327 * lyd_unlink() and lyd_free() functions).
328 *
329 * - @subpage howtodataparsers
330 * - @subpage howtodatamanipulators
331 * - @subpage howtodataprinters
332 *
333 * \note API for this group of functions is described in the [Data Instances module](@ref datatree).
334 *
335 * Functions List (not assigned to above subsections)
336 * --------------------------------------------------
337 * - lyd_get_node()
Michal Vasko105cef12016-02-04 12:06:26 +0100338 * - lyd_get_node2()
Michal Vasko6a1ab6f2016-02-04 12:08:11 +0100339 * - lyd_get_list_keys()
Radek Krejcidef50022016-02-01 16:38:32 +0100340 */
341
342/**
Michal Vasko0f14ba62016-03-21 15:38:11 +0100343 * @page howtoxpath XPath Addressing
344 *
345 * Internally, XPath evaluation is performed on \b when and \b must conditions in the schema. For that almost
346 * a full XPath 1.0 evaluator was implemented. This XPath implementation is available on data trees by calling
347 * lyd_get_node() except that only node sets are returned. This XPath conforms to the YANG specification
348 * (RFC 6020 section 6.4).
349 *
350 * A very small subset of this full XPath is recognized by lyd_new_path(). Basically, only a relative or absolute
351 * path can be specified to identify a new data node. However, lists must be identified by all their keys and created
352 * with all of them, so for those cases predicates are allowed. Predicates must be ordered the way the keys are ordered
353 * and all the keys must be specified. Every predicate includes a single key with its value. These paths are valid XPath
354 * expressions. Example:
355 *
356 * - /ietf-yang-library:modules-state/module[name='ietf-yang-library'][revision='']/submodules
357 *
358 * Almost the same XPath is accepted by ly_ctx_get_node(). The difference is that it is not used on data, but schema,
359 * which means there are no key values and only one node for one path. In effect, lists do not have to have any
360 * predicates. If they do, they do not need to have all the keys specified and if values are included, they are ignored.
361 * Nevertheless, any such expression is still a valid XPath, but can return more nodes if executed on a data tree.
362 * Examples (all returning the same node):
363 *
364 * - /ietf-yang-library:modules-state/module/submodules
365 * - /ietf-yang-library:modules-state/module[name]/submodules
366 * - /ietf-yang-library:modules-state/module[name][revision]/submodules
367 * - /ietf-yang-library:modules-state/module[name='ietf-yang-library'][revision]/submodules
368 *
369 * Functions List
370 * --------------
371 * - lyd_get_node()
372 * - lyd_new_path()
373 * - ly_ctx_get_node()
374 */
375
376/**
Radek Krejcidef50022016-02-01 16:38:32 +0100377 * @page howtodataparsers Parsing Data
378 *
379 * Data parser allows to read instances from a specific format. libyang supports the following data formats:
380 *
381 * - XML
382 *
383 * Original data format used in NETCONF protocol. XML mapping is part of the YANG specification
384 * ([RFC 6020](http://tools.ietf.org/html/rfc6020)).
385 *
386 * - JSON
387 *
388 * The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG
389 * can be found in [this draft](https://tools.ietf.org/html/draft-ietf-netmod-yang-json-05).
390 *
391 * Besides the format of input data, the parser functions accepts additional [options](@ref parseroptions) to specify
392 * how the input data should be processed.
393 *
394 * In contrast to the schema parser, data parser also accepts empty input data if such an empty data tree is valid
395 * according to the schemas in the libyang context.
396 *
397 * In case of XML input data, there is one additional way to parse input data. Besides parsing the data from a string
398 * in memory or a file, caller is able to build an XML tree using [libyang XML parser](@ref howtoxml) and then use
399 * this tree (or a part of it) as input to the lyd_parse_xml() function.
400 *
401 * Functions List
402 * --------------
Radek Krejci722b0072016-02-01 17:09:45 +0100403 * - lyd_parse_mem()
Radek Krejcidef50022016-02-01 16:38:32 +0100404 * - lyd_parse_fd()
405 * - lyd_parse_path()
406 * - lyd_parse_xml()
407 */
408
409/**
410 * @page howtodatamanipulators Manipulating Data
411 *
412 * There are many functions to create or modify an existing data tree. You can add new nodes, reconnect nodes from
413 * one tree to another (or e.g. from one list instance to another) or remove nodes. The functions doesn't allow you
414 * to put a node to a wrong place (by checking the module), but not all validation checks can be made directly
415 * (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 +0100416 * there is lyd_validate() function supposed to be called to make sure that the current data tree is valid. If
417 * working with RPCs, they are invalid also in case the data nodes are not ordered according to the schema, which
418 * you can fix easily with lyd_schema_sort(). Note, that not performing validation after some data tree changes
419 * can cause failure of various libyang functions later.
Radek Krejcidef50022016-02-01 16:38:32 +0100420 *
Michal Vasko0f14ba62016-03-21 15:38:11 +0100421 * Creating data is generally possible in two ways, they can be combined. You can add nodes one-by-one based on
Michal Vaskof748dbc2016-04-05 11:27:47 +0200422 * the node name and/or its parent (lyd_new(), lyd_new_anyxml_*(), lyd_new_leaf(), adn their output variants) or
Michal Vasko58f74f12016-03-24 13:26:06 +0100423 * address the nodes using a simple XPath addressing (lyd_new_path()). The latter enables to create a whole path
424 * of nodes, requires less information about the modified data, and is generally simpler to use. The path format
425 * specifics can be found [here](@ref howtoxpath).
Michal Vasko0f14ba62016-03-21 15:38:11 +0100426 *
Radek Krejcidef50022016-02-01 16:38:32 +0100427 * Also remember, that when you are creating/inserting a node, all the objects in that operation must belong to the
428 * same context.
429 *
430 * Modifying the single data tree in multiple threads is not safe.
431 *
432 * Functions List
433 * --------------
434 * - lyd_dup()
435 * - lyd_change_leaf()
436 * - lyd_insert()
437 * - lyd_insert_before()
438 * - lyd_insert_after()
439 * - lyd_insert_attr()
440 * - lyd_new()
Michal Vaskof748dbc2016-04-05 11:27:47 +0200441 * - lyd_new_anyxml_str()
442 * - lyd_new_anyxml_xml()
Radek Krejcidef50022016-02-01 16:38:32 +0100443 * - lyd_new_leaf()
Michal Vaskof5299282016-03-16 13:32:02 +0100444 * - lyd_new_path()
Radek Krejcidef50022016-02-01 16:38:32 +0100445 * - lyd_output_new()
Michal Vaskof748dbc2016-04-05 11:27:47 +0200446 * - lyd_output_new_anyxml_str()
447 * - lyd_output_new_anyxml_xml()
Radek Krejcidef50022016-02-01 16:38:32 +0100448 * - lyd_output_new_leaf()
449 * - lyd_unlink()
450 * - lyd_free()
451 * - lyd_free_attr()
452 * - lyd_free_withsiblings()
453 * - lyd_validate()
454 */
455
456/**
457 * @page howtodataprinters Printing Data
458 *
459 * Schema printers allows to serialize internal representation of a schema module in a specific format. libyang
460 * supports the following schema formats for printing:
461 *
462 * - XML
463 *
464 * Basic format as specified in rules of mapping YANG modeled data to XML in
465 * [RFC 6020](http://tools.ietf.org/html/rfc6020). It is possible to specify if
466 * the indentation will be used.
467 *
468 * - JSON
469 *
470 * The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG
471 * can be found in [this draft](https://tools.ietf.org/html/draft-ietf-netmod-yang-json-05).
472 *
473 * Printer functions allow to print to the different outputs including a callback function which allows caller
474 * to have a full control of the output data - libyang passes to the callback a private argument (some internal
475 * data provided by a caller of lyd_print_clb()), string buffer and number of characters to print. Note that the
476 * callback is supposed to be called multiple times during the lyd_print_clb() execution.
477 *
478 * Functions List
479 * --------------
480 * - lyd_print_mem()
481 * - lyd_print_fd()
482 * - lyd_print_file()
483 * - lyd_print_clb()
484 */
485
486/**
487 * @page howtoxml libyang XML Support
488 *
489 * libyang XML parser is able to parse XML documents used to represent data modeled by YANG. Therefore, there are
490 * some limitations in comparison to a full-featured XML parsers:
491 * - comments are ignored
492 * - Doctype declaration is ignored
493 * - CData sections are ignored
494 * - Process Instructions (PI) are ignored
495 *
496 * The API is designed to almost only read-only access. You can simply load XML document, go through the tree as
497 * you wish and dump the tree to an output. The only "write" functions are lyxml_free() and lyxml_unlink() to remove
498 * part of the tree or to unlink (separate) a subtree.
499 *
500 * XML parser is also used internally by libyang for parsing YIN schemas and data instances in XML format.
501 *
502 * \note API for this group of functions is described in the [XML Parser module](@ref xmlparser).
503 *
504 * Functions List
505 * --------------
Radek Krejci722b0072016-02-01 17:09:45 +0100506 * - lyxml_parse_mem()
507 * - lyxml_parse_path()
Radek Krejcidef50022016-02-01 16:38:32 +0100508 * - lyxml_get_attr()
509 * - lyxml_get_ns()
Radek Krejci722b0072016-02-01 17:09:45 +0100510 * - lyxml_print_mem()
511 * - lyxml_print_fd()
512 * - lyxml_print_file()
513 * - lyxml_print_clb()
Radek Krejcidef50022016-02-01 16:38:32 +0100514 * - lyxml_unlink()
515 * - lyxml_free()
516 */
517
518/**
519 * @page howtothreads libyang in Threads
520 *
521 * libyang can be used in multithreaded application keeping in mind the following rules:
522 * - libyang context manipulation (adding new schemas) is not thread safe and it is supposed to be done in a main
523 * thread before any other work with context, schemas or data instances. And destroying the context is supposed to
524 * be done when no other thread accesses context, schemas nor data trees
525 * - Data parser (\b lyd_parse*() functions) can be used simultaneously in multiple threads (also the returned
526 * #ly_errno is thread safe).
527 * - Modifying (lyd_new(), lyd_insert(), lyd_unlink(), lyd_free() and many other functions) a single data tree is not
528 * thread safe.
Radek Krejci26715a42015-07-29 14:10:45 +0200529 */
Radek Krejci94ca54b2015-07-08 15:48:47 +0200530
Radek Krejcida04f4a2015-05-21 12:54:09 +0200531/**
Radek Krejci26715a42015-07-29 14:10:45 +0200532 *
533 * @page howtologger Logger
534 *
535 * There are 4 verbosity levels defined as ::LY_LOG_LEVEL. The level can be
536 * changed by the ly_verb() function. By default, the verbosity level is
537 * set to #LY_LLERR value.
538 *
539 * In case the logger has an error message (LY_LLERR) to print, also an error
540 * code is recorded in extern ly_errno variable. Possible values are of type
541 * ::LY_ERR.
542 *
Radek Krejcidef50022016-02-01 16:38:32 +0100543 * \note API for this group of functions is described in the [logger module](@ref logger).
544 *
545 * Functions List
546 * --------------
547 * - ly_verb()
548 * - ly_set_log_clb()
549 * - ly_get_log_clb()
Radek Krejci26715a42015-07-29 14:10:45 +0200550 */
551
552/**
553 * @defgroup context Context
Radek Krejci3045cf32015-05-28 10:58:52 +0200554 * @{
555 *
Radek Krejci26715a42015-07-29 14:10:45 +0200556 * Structures and functions to manipulate with the libyang "containers". The \em context concept allows callers
557 * to work in environments with different sets of YANG schemas. More detailed information can be found at
558 * @ref howtocontext page.
Radek Krejci3045cf32015-05-28 10:58:52 +0200559 */
560
561/**
Radek Krejcida04f4a2015-05-21 12:54:09 +0200562 * @brief libyang context handler.
563 */
564struct ly_ctx;
565
566/**
567 * @brief Create libyang context
568 *
Radek Krejci26715a42015-07-29 14:10:45 +0200569 * Context is used to hold all information about schemas. Usually, the application is supposed
Radek Krejci91b833c2015-09-04 11:49:43 +0200570 * to work with a single context in which libyang is holding all schemas (and other internal
571 * information) according to which the data trees will be processed and validated. So, the schema
572 * trees are tightly connected with the specific context and they are held by the context internally
573 * - caller does not need to keep pointers to the schemas returned by lys_parse(), context knows
574 * about them. The data trees created with lyd_parse() are still connected with the specific context,
575 * but they are not internally held by the context. The data tree just points and lean on some data
576 * held by the context (schema tree, string dictionary, etc.). Therefore, in case of data trees, caller
577 * is supposed to keep pointers returned by the lyd_parse() and manage the data tree on its own. This
578 * also affects the number of instances of both tree types. While you can have only one instance of
579 * specific schema connected with a single context, number of data tree instances is not connected.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200580 *
Radek Krejci26715a42015-07-29 14:10:45 +0200581 * @param[in] search_dir Directory where libyang will search for the imported or included modules
582 * and submodules. If no such directory is available, NULL is accepted.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200583 *
Radek Krejci3045cf32015-05-28 10:58:52 +0200584 * @return Pointer to the created libyang context, NULL in case of error.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200585 */
586struct ly_ctx *ly_ctx_new(const char *search_dir);
587
588/**
Michal Vasko60ba9a62015-07-03 14:42:31 +0200589 * @brief Change the search path in libyang context
590 *
591 * @param[in] ctx Context to be modified.
592 * @param[in] search_dir New search path to replace the current one in ctx.
593 */
594void ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir);
595
596/**
Radek Krejci5a797572015-10-21 15:45:45 +0200597 * @brief Get current value of the search path in libyang context
598 *
599 * @param[in] ctx Context to query.
600 * @return Current value of the search path.
601 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100602const char *ly_ctx_get_searchdir(const struct ly_ctx *ctx);
Radek Krejci5a797572015-10-21 15:45:45 +0200603
604/**
Radek Krejci7ab25152015-08-07 14:48:45 +0200605 * @brief Get data of an internal ietf-yang-library module.
606 *
607 * @param[in] ctx Context with the modules.
608 * @return Root data node corresponding to the model, NULL on error.
609 * Caller is responsible for freeing the returned data tree using lyd_free().
610 */
611struct lyd_node *ly_ctx_info(struct ly_ctx *ctx);
612
613/**
Michal Vaskod7957c02016-04-01 10:27:26 +0200614 * @brief Iterate over all modules in a context.
615 *
616 * @param[in] ctx Context with the modules.
617 * @param[in,out] idx Index of the next module to be returned. Value of 0 starts from the beginning.
618 * @return Next context module, NULL if the last was already returned.
619 */
620const struct lys_module *ly_ctx_get_module_iter(const struct ly_ctx *ctx, uint32_t *idx);
621
622/**
Radek Krejcifd4e6e32015-08-10 15:00:51 +0200623 * @brief Get pointer to the schema tree of the module of the specified name.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200624 *
Radek Krejcida04f4a2015-05-21 12:54:09 +0200625 * @param[in] ctx Context to work in.
626 * @param[in] name Name of the YANG module to get.
Radek Krejcif647e612015-07-30 11:36:07 +0200627 * @param[in] revision Optional revision date of the YANG module to get. If not specified,
628 * the schema in the newest revision is returned if any.
629 * @return Pointer to the data model structure, NULL if no schema following the name and
Radek Krejcifd4e6e32015-08-10 15:00:51 +0200630 * revision requirements is present in the context.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200631 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100632const 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 +0200633
634/**
Radek Krejci21601a32016-03-07 11:39:27 +0100635 * @brief Get pointer to the older schema tree to the specified one in the provided context.
636 *
637 * The module is not necessarily from the provided \p ctx. If there are multiple schemas older than the
638 * provided one, the newest of them is returned.
639 *
640 * The function can be used in combination with ly_ctx_get_module() to get all revisions of a module in a context:
641 * \code{.c}
642 * for (mod = ly_ctx_get_module(ctx, name, NULL); mod; mod = ly_ctx_get_module_older(ctx, mod)) {
643 * ...
644 * }
645 * \endcode
646 *
647 * @param[in] ctx Context to work in.
648 * @param[in] module YANG module to compare with
649 * @return Pointer to the data model structure, NULL if no older schema is present in the context.
650 */
651const struct lys_module *ly_ctx_get_module_older(const struct ly_ctx *ctx, const struct lys_module *module);
652
653/**
Michal Vasko99b0aad2015-12-01 12:28:51 +0100654 * @brief Try to find the model in the searchpath of \p ctx and load it into it. If custom missing
655 * module callback is set, it is used instead.
Michal Vasko82465962015-11-10 11:03:11 +0100656 *
657 * @param[in] ctx Context to add to.
Michal Vasko82465962015-11-10 11:03:11 +0100658 * @param[in] name Name of the module to load.
659 * @param[in] revision Optional revision date of the module. If not specified, it is
660 * assumed that there is only one model revision in the searchpath (the first matching file
661 * is parsed).
662 * @return Pointer to the data model structure, NULL if not found or some error occured.
663 */
Michal Vasko99b0aad2015-12-01 12:28:51 +0100664const struct lys_module *ly_ctx_load_module(struct ly_ctx *ctx, const char *name, const char *revision);
665
666/**
667 * @brief Callback for retrieving missing included or imported models in a custom way.
668 *
669 * @param[in] name Missing module name.
670 * @param[in] revision Optional missing module revision.
671 * @param[in] user_data User-supplied callback data.
672 * @param[out] format Format of the returned module data.
Michal Vasko880dceb2016-03-03 15:44:56 +0100673 * @param[out] free_module_data Callback for freeing the returned module data. If not set, the data will be left untouched.
Michal Vasko99b0aad2015-12-01 12:28:51 +0100674 * @return Requested module data or NULL on error.
675 */
676typedef char *(*ly_module_clb)(const char *name, const char *revision, void *user_data, LYS_INFORMAT *format,
Michal Vaskod3e975b2016-03-03 15:40:21 +0100677 void (**free_module_data)(void *model_data));
Michal Vasko99b0aad2015-12-01 12:28:51 +0100678
679/**
680 * @brief Set missing include or import model callback.
681 *
682 * @param[in] ctx Context that will use this callback.
683 * @param[in] clb Callback responsible for returning a missing model.
684 * @param[in] user_data Arbitrary data that will always be passed to the callback \p clb.
685 */
686void ly_ctx_set_module_clb(struct ly_ctx *ctx, ly_module_clb clb, void *user_data);
687
688/**
689 * @brief Get the custom callback for missing module retrieval.
690 *
691 * @param[in] ctx Context to read from.
692 * @param[in] user_data Optional pointer for getting the user-supplied callbck data.
693 * @return Custom user missing module callback or NULL if not set.
694 */
695ly_module_clb ly_ctx_get_module_clb(const struct ly_ctx *ctx, void **user_data);
Michal Vasko82465962015-11-10 11:03:11 +0100696
697/**
Radek Krejcifd4e6e32015-08-10 15:00:51 +0200698 * @brief Get pointer to the schema tree of the module of the specified namespace
699 *
700 * @param[in] ctx Context to work in.
701 * @param[in] ns Namespace of the YANG module to get.
702 * @param[in] revision Optional revision date of the YANG module to get. If not specified,
703 * the schema in the newest revision is returned if any.
704 * @return Pointer to the data model structure, NULL if no schema following the namespace and
705 * revision requirements is present in the context.
706 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100707const 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 +0200708
709/**
Radek Krejci62f0da72016-03-07 11:35:43 +0100710 * @brief Get submodule of a main module.
711 *
712 * 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 +0200713 *
Radek Krejcia7533f22016-03-07 07:37:45 +0100714 * @param[in] ctx Context to work in.
Michal Vaskof6d94c62016-04-05 11:21:54 +0200715 * @param[in] module Name of the main (belongs-to) module. If NULL, all module submodules are searched.
716 * @param[in] revision Optional revision date of \p module. If NULL, all revisions of \p module
717 * are searched. If set, \p module must also be set.
Radek Krejcia7533f22016-03-07 07:37:45 +0100718 * @param[in] submodule Name of the submodule to get.
Michal Vaskof6d94c62016-04-05 11:21:54 +0200719 * @param[in] sub_revision Optional revision date of \p submodule. If NULL, the newest revision of \p submodule
720 * is returned.
Michal Vasko7bf06882015-07-03 15:33:56 +0200721 * @return Pointer to the data model structure.
722 */
Radek Krejcia7533f22016-03-07 07:37:45 +0100723const 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 +0200724 const char *submodule, const char *sub_revision);
Michal Vasko7bf06882015-07-03 15:33:56 +0200725
726/**
Radek Krejci62f0da72016-03-07 11:35:43 +0100727 * @brief Get submodule of a main module.
728 *
729 * If you have only the name (and optionally revision) of the submodule's main module, use ly_ctx_get_submodule()
730 * instead.
731 *
732 * @param[in] main_module Main module (belongs to) of the searched submodule.
733 * @param[in] submodule Name of the submodule to get.
734 * @return Pointer to the data model structure.
735 */
736const struct lys_submodule *ly_ctx_get_submodule2(const struct lys_module *main_module, const char *submodule);
737
738/**
Michal Vasko3547c532016-03-14 09:40:50 +0100739 * @brief Get schema node according to the given schema node identifier in JSON format.
Michal Vasko3edeaf72016-02-11 13:17:43 +0100740 *
Michal Vasko3547c532016-03-14 09:40:50 +0100741 * If the \p nodeid is absolute, the first node identifier must be prefixed with
742 * the module name. Then every other identifier either has an explicit module name or
743 * the module name of the previous node is assumed. Examples:
Michal Vasko3edeaf72016-02-11 13:17:43 +0100744 *
745 * /ietf-netconf-monitoring:get-schema/input/identifier
746 * /ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address/ip
747 *
Michal Vasko3547c532016-03-14 09:40:50 +0100748 * If the \p nodeid is relative, \p start is mandatory and is the starting point
749 * for the resolution. The first node identifier does not need a module name.
750 *
Michal Vasko3edeaf72016-02-11 13:17:43 +0100751 * @param[in] ctx Context to work in.
Michal Vasko3547c532016-03-14 09:40:50 +0100752 * @param[in] start Starting node for a relative schema node identifier, in which
753 * case it is mandatory.
754 * @param[in] nodeid JSON schema node identifier.
Michal Vasko3edeaf72016-02-11 13:17:43 +0100755 * @return Resolved schema node or NULL.
756 */
Michal Vasko3547c532016-03-14 09:40:50 +0100757const 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 +0100758
759/**
Radek Krejci3045cf32015-05-28 10:58:52 +0200760 * @brief Free all internal structures of the specified context.
761 *
762 * The function should be used before terminating the application to destroy
763 * and free all structures internally used by libyang. If the caller uses
764 * multiple contexts, the function should be called for each used context.
765 *
766 * All instance data are supposed to be freed before destroying the context.
767 * Data models are destroyed automatically as part of ly_ctx_destroy() call.
768 *
769 * @param[in] ctx libyang context to destroy
Radek Krejcifa0b5e02016-02-04 13:57:03 +0100770 * @param[in] private_destructor Optional destructor function for private objects assigned
771 * to the nodes via lys_set_private(). If NULL, the private objects are not freed by libyang.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200772 */
Radek Krejcifa0b5e02016-02-04 13:57:03 +0100773void ly_ctx_destroy(struct ly_ctx *ctx, void (*private_destructor)(const struct lys_node *node, void *priv));
Radek Krejcida04f4a2015-05-21 12:54:09 +0200774
Radek Krejci26715a42015-07-29 14:10:45 +0200775/**@} context */
776
777/**
Radek Krejcidef50022016-02-01 16:38:32 +0100778 * @defgroup nodeset Tree nodes set
Radek Krejcidc154432016-01-21 11:10:59 +0100779 * @ingroup datatree
780 * @ingroup schematree
781 * @{
782 *
Radek Krejcidef50022016-02-01 16:38:32 +0100783 * Structure and functions to hold and manipulate with sets of nodes from schema or data trees.
784 */
785
786/**
Radek Krejci8f08df12016-03-21 11:11:30 +0100787 * @brief set array of ::ly_set
788 * It is kept in union to keep ::ly_set generic for data as well as schema trees
789 */
790union ly_set_set {
791 struct lys_node **s; /**< array of pointers to a ::lys_node objects */
792 struct lyd_node **d; /**< array of pointers to a ::lyd_node objects */
793 void **g; /**< dummy array for generic work */
794};
795
796/**
Radek Krejcidc154432016-01-21 11:10:59 +0100797 * @brief Structure to hold a set of (not necessary somehow connected) ::lyd_node or ::lys_node objects.
798 * Caller is supposed to not mix the type of objects added to the set and according to its knowledge about
799 * the set content, it is supposed to access the set via the sset, dset or set members of the structure.
800 *
Radek Krejcidef50022016-02-01 16:38:32 +0100801 * To free the structure, use ly_set_free() function, to manipulate with the structure, use other
802 * ly_set_* functions.
Radek Krejcidc154432016-01-21 11:10:59 +0100803 */
804struct ly_set {
805 unsigned int size; /**< allocated size of the set array */
806 unsigned int number; /**< number of elements in (used size of) the set array */
Radek Krejci8f08df12016-03-21 11:11:30 +0100807 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 +0100808};
809
810/**
Radek Krejcidef50022016-02-01 16:38:32 +0100811 * @brief Create and initiate new ::ly_set structure.
Radek Krejcidc154432016-01-21 11:10:59 +0100812 *
Radek Krejcidef50022016-02-01 16:38:32 +0100813 * @return Created ::ly_set structure or NULL in case of error.
Radek Krejcidc154432016-01-21 11:10:59 +0100814 */
815struct ly_set *ly_set_new(void);
816
817/**
818 * @brief Add a ::lyd_node or ::lys_node object into the set
819 *
820 * @param[in] set Set where the \p node will be added.
821 * @param[in] node The ::lyd_node or ::lys_node object to be added into the \p set;
822 * @return 0 on success
823 */
824int ly_set_add(struct ly_set *set, void *node);
825
826/**
827 * @brief Remove a ::lyd_node or ::lys_node object from the set.
828 *
829 * Note that after removing a node from a set, indexes of other nodes in the set can change
830 * (the last object is placed instead of the removed object).
831 *
832 * @param[in] set Set from which the \p node will be removed.
833 * @param[in] node The ::lyd_node or ::lys_node object to be removed from the \p set;
834 * @return 0 on success
835 */
836int ly_set_rm(struct ly_set *set, void *node);
837
838/**
839 * @brief Remove a ::lyd_node or ::lys_node object from the set index.
840 *
841 * Note that after removing a node from a set, indexes of other nodes in the set can change
842 * (the last object is placed instead of the removed object).
843 *
844 * @param[in] set Set from which a node will be removed.
845 * @param[in] index Index of the ::lyd_node or ::lys_node object in the \p set to be removed from the \p set;
846 * @return 0 on success
847 */
848int ly_set_rm_index(struct ly_set *set, unsigned int index);
849
850/**
Radek Krejcidef50022016-02-01 16:38:32 +0100851 * @brief Free the ::ly_set data. Frees only the set structure content, not the referred data.
Radek Krejcidc154432016-01-21 11:10:59 +0100852 *
853 * @param[in] set The set to be freed.
854 */
855void ly_set_free(struct ly_set *set);
856
Radek Krejcidef50022016-02-01 16:38:32 +0100857/**@} nodeset */
Radek Krejci6140e4e2015-10-09 15:50:55 +0200858
859/**
Radek Krejci5044be32016-01-18 17:05:51 +0100860 * @defgroup printerflags Printer flags
Radek Krejcidef50022016-02-01 16:38:32 +0100861 * @ingroup datatree
Radek Krejci5044be32016-01-18 17:05:51 +0100862 *
863 * Validity flags for data nodes.
864 *
865 * @{
866 */
867#define LYP_WITHSIBLINGS 0x01 /**< Flag for printing also the (following) sibling nodes of the data node. */
Michal Vasko95068c42016-03-24 14:58:11 +0100868#define LYP_FORMAT 0x02 /**< Flag for formatted output. */
Radek Krejci5044be32016-01-18 17:05:51 +0100869
870/**
871 * @}
872 */
873
874/**
Radek Krejci3045cf32015-05-28 10:58:52 +0200875 * @defgroup logger Logger
876 * @{
877 *
878 * Publicly visible functions and values of the libyang logger. For more
879 * information, see \ref howtologger.
880 */
881
882/**
883 * @typedef LY_LOG_LEVEL
884 * @brief Verbosity levels of the libyang logger.
885 */
886typedef enum {
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200887 LY_LLERR, /**< Print only error messages. */
888 LY_LLWRN, /**< Print error and warning messages. */
889 LY_LLVRB, /**< Besides errors and warnings, print some other verbose messages. */
890 LY_LLDBG /**< Print all messages including some development debug messages. */
Radek Krejci3045cf32015-05-28 10:58:52 +0200891} LY_LOG_LEVEL;
892
893/**
894 * @brief Set logger verbosity level.
895 * @param[in] level Verbosity level.
896 */
897void ly_verb(LY_LOG_LEVEL level);
898
899/**
Michal Vaskof1d62cf2015-12-07 13:17:11 +0100900 * @brief Set logger callback.
901 * @param[in] clb Logging callback.
Radek Krejciadb57612016-02-16 13:34:34 +0100902 * @param[in] path flag to resolve and provide path as the third parameter of the callback function. In case of
903 * validation and some other errors, it can be useful to get the path to the problematic element. Note,
904 * that according to the tree type and the specific situation, the path can slightly differs (keys
905 * presence) or it can be NULL, so consider it as an optional parameter. If the flag is 0, libyang will
906 * not bother with resolving the path.
Michal Vaskof1d62cf2015-12-07 13:17:11 +0100907 */
Radek Krejciadb57612016-02-16 13:34:34 +0100908void 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 +0100909
910/**
911 * @brief Get logger callback.
912 * @return Logger callback (can be NULL).
913 */
Radek Krejciadb57612016-02-16 13:34:34 +0100914void (*ly_get_log_clb(void))(LY_LOG_LEVEL, const char *, const char *);
Michal Vaskof1d62cf2015-12-07 13:17:11 +0100915
916/**
Radek Krejci3045cf32015-05-28 10:58:52 +0200917 * @typedef LY_ERR
Radek Krejci26715a42015-07-29 14:10:45 +0200918 * @brief libyang's error codes available via ly_errno extern variable.
Radek Krejci9b4ca392015-04-10 08:31:27 +0200919 * @ingroup logger
920 */
921typedef enum {
Radek Krejciae6817a2015-08-10 14:02:06 +0200922 LY_SUCCESS, /**< no error, not set by functions, included just to complete #LY_ERR enumeration */
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200923 LY_EMEM, /**< Memory allocation failure */
924 LY_ESYS, /**< System call failure */
925 LY_EINVAL, /**< Invalid value */
926 LY_EINT, /**< Internal error */
927 LY_EVALID /**< Validation failure */
Radek Krejci3045cf32015-05-28 10:58:52 +0200928} LY_ERR;
Radek Krejci7d9f46a2016-01-29 13:53:18 +0100929
Radek Krejci26715a42015-07-29 14:10:45 +0200930/**
Michal Vaskof5035ce2016-03-11 10:21:31 +0100931 * @typedef LY_VECODE
932 * @brief libyang's codes of validation error. Whenever ly_errno is set to LY_EVALID, the ly_vecode is also set
933 * to the appropriate LY_VECODE value.
Radek Krejcia37b39c2016-03-09 16:38:18 +0100934 * @ingroup logger
935 */
936typedef enum {
Michal Vaskof5035ce2016-03-11 10:21:31 +0100937 LYVE_SUCCESS = 0, /**< no error */
Radek Krejcia37b39c2016-03-09 16:38:18 +0100938
Michal Vaskof5035ce2016-03-11 10:21:31 +0100939 LYVE_XML_MISS, /**< missing XML object */
940 LYVE_XML_INVAL, /**< invalid XML object */
941 LYVE_XML_INCHAR, /**< invalid XML character */
Radek Krejcia37b39c2016-03-09 16:38:18 +0100942
Michal Vaskof5035ce2016-03-11 10:21:31 +0100943 LYVE_EOF, /**< unexpected end of input data */
944 LYVE_INSTMT, /**< invalid statement (schema) */
945 /* */
946 LYVE_INID, /**< invalid identifier (schema) */
947 LYVE_INDATE, /**< invalid date format */
948 LYVE_INARG, /**< invalid value of a statement argument (schema) */
949 LYVE_MISSSTMT, /**< missing required statement (schema) */
950 /* */
951 LYVE_MISSARG, /**< missing required statement argument (schema) */
952 LYVE_TOOMANY, /**< too many instances of some object */
953 LYVE_DUPID, /**< duplicated identifier (schema) */
954 LYVE_DUPLEAFLIST, /**< multiple instances of leaf-list */
955 LYVE_DUPLIST, /**< multiple instances of list */
956 LYVE_ENUM_DUPVAL, /**< duplicated enum value (schema) */
957 LYVE_ENUM_DUPNAME, /**< duplicated enum name (schema) */
958 LYVE_ENUM_WS, /**< enum name with leading/trailing whitespaces (schema) */
959 LYVE_BITS_DUPVAL, /**< duplicated bits value (schema) */
960 LYVE_BITS_DUPNAME, /**< duplicated bits name (schema) */
961 LYVE_INMOD, /**< invalid module name */
962 /* */
963 LYVE_KEY_NLEAF, /**< list key is not a leaf (schema) */
964 LYVE_KEY_TYPE, /**< invalid list key type (schema) */
965 LYVE_KEY_CONFIG, /**< key config value differs from the list config value */
966 LYVE_KEY_MISS, /**< list key not found (schema) */
967 LYVE_KEY_DUP, /**< duplicated key identifier (schema) */
968 LYVE_INREGEX, /**< invalid regular expression (schema) */
969 LYVE_INRESOLV, /**< no resolvents found (schema) */
970 LYVE_INSTATUS, /**< invalid derivation because of status (schema) */
Radek Krejcia37b39c2016-03-09 16:38:18 +0100971
Michal Vaskof5035ce2016-03-11 10:21:31 +0100972 LYVE_OBSDATA, /**< obsolete data instantiation (data) */
973 /* */
974 LYVE_NORESOLV, /**< no resolvents found for an expression (data) */
975 LYVE_INELEM, /**< invalid element (data) */
976 /* */
977 LYVE_MISSELEM, /**< missing required element (data) */
978 LYVE_INVAL, /**< invalid value of an element (data) */
979 LYVE_INATTR, /**< invalid attribute in an element (data) */
980 LYVE_MISSATTR, /**< missing attribute in an element (data) */
981 LYVE_OORVAL, /**< value out of range/length (data) */
982 LYVE_INCHAR, /**< unexpected characters (data) */
983 LYVE_INPRED, /**< predicate resolution fail (data) */
984 LYVE_MCASEDATA, /**< data for more cases of a choice (data) */
985 LYVE_NOCOND, /**< unsatisfied must/when condition (data) */
986 LYVE_INORDER, /**< invalid order of elements (data) */
987 LYVE_INCOUNT, /**< invalid number of elements (data) */
Radek Krejci03b71f72016-03-16 11:10:09 +0100988 LYVE_INWHEN, /**< irresolvable when condition (data) */
Radek Krejcia37b39c2016-03-09 16:38:18 +0100989
Michal Vaskof5035ce2016-03-11 10:21:31 +0100990 LYVE_XPATH_INTOK, /**< unexpected XPath token */
991 LYVE_XPATH_EOF, /**< unexpected end of an XPath expression */
992 LYVE_XPATH_INOP, /**< invalid XPath operation operands */
993 /* */
994 LYVE_XPATH_INCTX, /**< invalid XPath context type */
995 LYVE_XPATH_INARGCOUNT, /**< invalid number of arguments for an XPath function */
Michal Vasko6fae1362016-03-11 15:10:00 +0100996 LYVE_XPATH_INARGTYPE, /**< invalid type of arguments for an XPath function */
997
998 LYVE_PATH_INCHAR, /**< invalid characters (path) */
Michal Vaskoe733d682016-03-14 09:08:27 +0100999 LYVE_PATH_INMOD, /**< invalid module name (path) */
1000 LYVE_PATH_MISSMOD, /**< missing module name (path) */
Michal Vasko6fae1362016-03-11 15:10:00 +01001001 LYVE_PATH_INNODE, /**< invalid node name (path) */
Michal Vasko6fae1362016-03-11 15:10:00 +01001002 LYVE_PATH_INKEY, /**< invalid key name (path) */
1003 LYVE_PATH_MISSKEY, /**< missing some list keys (path) */
1004 LYVE_PATH_EXISTS, /**< target node already exists (path) */
1005 LYVE_PATH_MISSPAR, /**< some parent of the target node is missing (path) */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001006} LY_VECODE;
Radek Krejcia37b39c2016-03-09 16:38:18 +01001007
1008/**
Radek Krejci7d9f46a2016-01-29 13:53:18 +01001009 * @cond INTERNAL
Radek Krejci386714d2016-02-15 10:24:30 +01001010 * Get address of (thread-specific) `ly_errno' variable.
Radek Krejci26715a42015-07-29 14:10:45 +02001011 */
Radek Krejci7d9f46a2016-01-29 13:53:18 +01001012LY_ERR *ly_errno_location(void);
1013
Michal Vaskof5035ce2016-03-11 10:21:31 +01001014LY_VECODE *ly_vecode_location(void);
Radek Krejcia37b39c2016-03-09 16:38:18 +01001015
Radek Krejci7d9f46a2016-01-29 13:53:18 +01001016/**
1017 * @endcond INTERNAL
Radek Krejcidef50022016-02-01 16:38:32 +01001018 * @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 +01001019 */
1020#define ly_errno (*ly_errno_location())
Radek Krejci9b4ca392015-04-10 08:31:27 +02001021
Radek Krejci386714d2016-02-15 10:24:30 +01001022/**
Radek Krejcia37b39c2016-03-09 16:38:18 +01001023 * @brief libyang's validation error code
1024 */
Michal Vaskof5035ce2016-03-11 10:21:31 +01001025#define ly_vecode (*ly_vecode_location())
Radek Krejcia37b39c2016-03-09 16:38:18 +01001026
1027/**
Radek Krejci386714d2016-02-15 10:24:30 +01001028 * @brief Get the last (thread-specific) error message.
Radek Krejci6e8fc0b2016-02-16 14:33:37 +01001029 *
1030 * Sometimes, the error message is extended with path of the element where is the problem.
1031 * The path is available via ly_errpath().
1032 *
Radek Krejci386714d2016-02-15 10:24:30 +01001033 * @return Text of the last error message.
1034 */
1035const char *ly_errmsg(void);
1036
Radek Krejci6e8fc0b2016-02-16 14:33:37 +01001037/**
1038 * @brief Get the last (thread-specific) path of the element where was an error.
1039 *
1040 * The path always corresponds to the error message available via ly_errmsg(), so
1041 * whenever a subsequent error message is printed, the path is erased or rewritten.
1042 *
1043 * @return Path of the error element.
1044 */
1045const char *ly_errpath(void);
1046
Radek Krejci3045cf32015-05-28 10:58:52 +02001047/**@} logger */
Radek Krejci9b4ca392015-04-10 08:31:27 +02001048
Radek Krejci39d8d0d2015-08-17 13:42:45 +02001049#ifdef __cplusplus
1050}
1051#endif
1052
Radek Krejci9b4ca392015-04-10 08:31:27 +02001053#endif /* LY_LIBYANG_H_ */