Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 1 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 2 | * @file libyang.h |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 4 | * @brief The main libyang public header. |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 5 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 6 | * Copyright (c) 2015-2016 CESNET, z.s.p.o. |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 7 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 8 | * 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 Vasko | 8de098c | 2016-02-26 10:00:25 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef LY_LIBYANG_H_ |
| 16 | #define LY_LIBYANG_H_ |
| 17 | |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 18 | #include <stdio.h> |
| 19 | |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 20 | #include "tree_schema.h" |
| 21 | #include "tree_data.h" |
Radek Krejci | c6704c8 | 2015-10-06 11:12:45 +0200 | [diff] [blame] | 22 | #include "xml.h" |
Radek Krejci | 41912fe | 2015-10-22 10:22:12 +0200 | [diff] [blame] | 23 | #include "dict.h" |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 24 | |
Radek Krejci | 39d8d0d | 2015-08-17 13:42:45 +0200 | [diff] [blame] | 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
Radek Krejci | 60cdf28 | 2016-10-10 16:22:22 +0200 | [diff] [blame] | 29 | #define LY_VERSION_MAJOR @LIBYANG_MAJOR_VERSION@ /**< libyang major version number */ |
| 30 | #define LY_VERSION_MINOR @LIBYANG_MINOR_VERSION@ /**< libyang minor version number */ |
| 31 | #define LY_VERSION_MICRO @LIBYANG_MICRO_VERSION@ /**< libyang micro version number */ |
| 32 | |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 33 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 34 | * @mainpage About |
| 35 | * |
| 36 | * libyang is a library implementing processing of the YANG schemas and data modeled by the YANG language. The |
| 37 | * library is implemented in C for GNU/Linux and provides C API. |
| 38 | * |
| 39 | * @section about-features Main Features |
| 40 | * |
Radek Krejci | b4e72e5 | 2016-04-13 15:10:51 +0200 | [diff] [blame] | 41 | * - Parsing (and validating) schemas in YANG format. |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 42 | * - Parsing (and validating) schemas in YIN format. |
| 43 | * - Parsing, validating and printing instance data in XML format. |
Radek Krejci | 3c73f49 | 2016-09-20 16:29:30 +0200 | [diff] [blame] | 44 | * - Parsing, validating and printing instance data in JSON format ([RFC 7951](https://tools.ietf.org/html/rfc7951)). |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 45 | * - Manipulation with the instance data. |
Radek Krejci | 3c73f49 | 2016-09-20 16:29:30 +0200 | [diff] [blame] | 46 | * - Support for default values in the instance data ([RFC 6243](https://tools.ietf.org/html/rfc6243)). |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 47 | * |
Radek Krejci | daa080f | 2016-10-05 08:38:09 +0200 | [diff] [blame] | 48 | * The current implementation covers YANG 1.0 ([RFC 6020](https://tools.ietf.org/html/rfc6020)) as well as |
| 49 | * YANG 1.1 ([RFC 7950](https://tools.ietf.org/html/rfc7950)). |
Radek Krejci | 8b13fc0 | 2016-04-18 13:08:04 +0200 | [diff] [blame] | 50 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 51 | * @subsection about-features-others Extra (side-effect) Features |
| 52 | * |
| 53 | * - XML parser. |
| 54 | * - Optimized string storage (dictionary). |
| 55 | * |
| 56 | * @section about-license License |
| 57 | * |
| 58 | * Copyright (c) 2015-2016 CESNET, z.s.p.o. |
| 59 | * |
| 60 | * (The BSD 3-Clause License) |
| 61 | * |
| 62 | * Redistribution and use in source and binary forms, with or without |
| 63 | * modification, are permitted provided that the following conditions |
| 64 | * are met: |
| 65 | * 1. Redistributions of source code must retain the above copyright |
| 66 | * notice, this list of conditions and the following disclaimer. |
| 67 | * 2. Redistributions in binary form must reproduce the above copyright |
| 68 | * notice, this list of conditions and the following disclaimer in |
| 69 | * the documentation and/or other materials provided with the |
| 70 | * distribution. |
| 71 | * 3. Neither the name of the Company nor the names of its contributors |
| 72 | * may be used to endorse or promote products derived from this |
| 73 | * software without specific prior written permission. |
| 74 | */ |
| 75 | |
| 76 | /** |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 77 | * @page howto How To ... |
| 78 | * |
| 79 | * - @subpage howtocontext |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 80 | * - @subpage howtoschemas |
| 81 | * - @subpage howtodata |
Michal Vasko | 0f14ba6 | 2016-03-21 15:38:11 +0100 | [diff] [blame] | 82 | * - @subpage howtoxpath |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 83 | * - @subpage howtoxml |
| 84 | * - @subpage howtothreads |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 85 | * - @subpage howtologger |
| 86 | */ |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 87 | |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 88 | /** @page howtocontext Context |
| 89 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 90 | * The context concept allows callers to work in environments with different sets of YANG schemas. |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 91 | * |
| 92 | * The first step in libyang is to create a new context using ly_ctx_new(). It returns a handler |
| 93 | * used in the following work. |
| 94 | * |
| 95 | * When creating a new context, search dir can be specified (NULL is accepted) to provide directory |
| 96 | * where libyang will automatically search for schemas being imported or included. The search path |
Radek Krejci | 1fbe858 | 2016-09-15 09:40:11 +0200 | [diff] [blame] | 97 | * can be later changed via ly_ctx_set_searchdir() function. If the search dir is specified, it is explored |
Radek Krejci | faa3a29 | 2016-11-13 10:11:29 +0900 | [diff] [blame] | 98 | * first. Except the searchpath, also all its subdirectories (and symlinks) are taken into account. In case |
| 99 | * the module is not found, libyang tries to find the (sub)module also in current working working directory. |
| 100 | * Note, that in this case only the current directory without any other subdirectory is examinde. This |
| 101 | * automatic searching can be completely avoided when the caller sets module searching callback |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 102 | * (#ly_module_clb) via ly_ctx_set_module_clb(). |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 103 | * |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 104 | * Schemas are added into the context using [parser functions](@ref howtoschemasparsers) - \b lys_parse_*(). |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 105 | * In case of schemas, also ly_ctx_load_module() can be used - in that case the #ly_module_clb or automatic |
Radek Krejci | 1fbe858 | 2016-09-15 09:40:11 +0200 | [diff] [blame] | 106 | * search in search dir and in the current working directory is used. |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 107 | * |
| 108 | * Similarly, data trees can be parsed by \b lyd_parse_*() functions. Note, that functions for schemas have \b lys_ |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 109 | * prefix while functions for instance data have \b lyd_ prefix. |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 110 | * |
Radek Krejci | ee67407 | 2016-09-15 10:37:40 +0200 | [diff] [blame] | 111 | * Context can hold multiple revisions of the same schema, but only one of them can be implemented. The schema is not |
| 112 | * implemented in case it is automatically loaded as import for another module and it is not referenced in such |
| 113 | * a module (and no other) as target of leafref, augment or deviation. All modules with deviation definition are always |
| 114 | * marked as implemented. The imported (not implemented) module can be set implemented by lys_set_implemented(). But |
| 115 | * the implemented module cannot be changed back to just imported module. The imported modules are used only as a |
| 116 | * source of definitions for types (including identities) and uses statements. The data in such a modules are |
| 117 | * ignored - caller is not allowed to create the data defined in the model via data parsers, the default nodes are |
| 118 | * not added into any data tree and mandatory nodes are not checked in the data trees. |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 119 | * |
Radek Krejci | 31fb8be | 2016-06-23 15:26:26 +0200 | [diff] [blame] | 120 | * Context holds all modules and their submodules internally. To get |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 121 | * a specific module or submodule, use ly_ctx_get_module() and ly_ctx_get_submodule(). There are some additional |
Radek Krejci | 31fb8be | 2016-06-23 15:26:26 +0200 | [diff] [blame] | 122 | * alternatives to these functions (with different parameters). If you need to do something with all the modules or |
Michal Vasko | 462be9a | 2016-04-05 11:24:08 +0200 | [diff] [blame] | 123 | * submodules in the context, it is advised to iterate over them using ly_ctx_get_module_iter(), it is |
| 124 | * the most efficient way. Alternatively, the ly_ctx_info() function can be used to get complex information |
| 125 | * about the schemas in the context in the form of data tree defined by |
Radek Krejci | bd9e8d2 | 2016-02-03 14:11:48 +0100 | [diff] [blame] | 126 | * <a href="https://tools.ietf.org/html/draft-ietf-netconf-yang-library-04">ietf-yang-library</a> schema. |
Michal Vasko | ac7f422 | 2016-09-21 09:02:29 +0200 | [diff] [blame] | 127 | * To get a specific node defined in a module in the context, ly_ctx_get_node() can be used. |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 128 | * |
Radek Krejci | 0ec51da | 2016-12-14 16:42:03 +0100 | [diff] [blame] | 129 | * Modules held by a context can be removed by ly_ctx_remove_module(). Besides removing the module, it is possible |
| 130 | * just to disable it with lys_set_disabled(). In this case the module is hidden in the context (disabled modules can |
| 131 | * be iterated via ly_ctx_get_disabled_module_iter()) and not used during the common work with the context. The module |
| 132 | * is enabled explicitly by calling lys_set_enabled() or implicitly by the request to load the schema (directly or |
| 133 | * indirectly via import of another module) into the context. |
| 134 | * |
| 135 | * To clean the context from all the loaded modules (except the [internal modules](@ref howtoschemasparsers)), the |
| 136 | * ly_ctx_clean() function can be used. To remove the context, there is ly_ctx_destroy() function. |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 137 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 138 | * - @subpage howtocontextdict |
| 139 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 140 | * \note API for this group of functions is available in the [context module](@ref context). |
| 141 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 142 | * Functions List |
| 143 | * -------------- |
| 144 | * - ly_ctx_new() |
| 145 | * - ly_ctx_set_searchdir() |
| 146 | * - ly_ctx_get_searchdir() |
| 147 | * - ly_ctx_set_module_clb() |
| 148 | * - ly_ctx_get_module_clb() |
| 149 | * - ly_ctx_load_module() |
| 150 | * - ly_ctx_info() |
Michal Vasko | d7957c0 | 2016-04-01 10:27:26 +0200 | [diff] [blame] | 151 | * - ly_ctx_get_module_iter() |
Radek Krejci | 0ec51da | 2016-12-14 16:42:03 +0100 | [diff] [blame] | 152 | * - ly_ctx_get_disabled_module_iter() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 153 | * - ly_ctx_get_module() |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 154 | * - ly_ctx_get_module_older() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 155 | * - ly_ctx_get_module_by_ns() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 156 | * - ly_ctx_get_submodule() |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 157 | * - ly_ctx_get_submodule2() |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 158 | * - ly_ctx_get_node() |
Radek Krejci | 0ec51da | 2016-12-14 16:42:03 +0100 | [diff] [blame] | 159 | * - ly_ctx_remove_module() |
| 160 | * - ly_ctx_clean() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 161 | * - ly_ctx_destroy() |
Radek Krejci | ee67407 | 2016-09-15 10:37:40 +0200 | [diff] [blame] | 162 | * - lys_set_implemented() |
Radek Krejci | 0ec51da | 2016-12-14 16:42:03 +0100 | [diff] [blame] | 163 | * - lys_set_disabled() |
| 164 | * - lys_set_enabled() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 165 | */ |
| 166 | |
| 167 | /** |
| 168 | * @page howtocontextdict Context Dictionary |
| 169 | * |
| 170 | * Context includes dictionary to store strings more effectively. The most of strings repeats quite often in schema |
| 171 | * as well as data trees. Therefore, instead of allocating those strings each time they appear, libyang stores them |
| 172 | * as records in the dictionary. The basic API to the context dictionary is public, so even a caller application can |
| 173 | * use the dictionary. |
| 174 | * |
| 175 | * To insert a string into the dictionary, caller can use lydict_insert() (adding a constant string) or |
| 176 | * lydict_insert_zc() (for dynamically allocated strings that won't be used by the caller after its insertion into |
| 177 | * the dictionary). Both functions return the pointer to the inserted string in the dictionary record. |
| 178 | * |
| 179 | * To remove (reference of the) string from the context dictionary, lydict_remove() is supposed to be used. |
| 180 | * |
| 181 | * \note Incorrect usage of the dictionary can break libyang functionality. |
| 182 | * |
| 183 | * \note API for this group of functions is described in the [XML Parser module](@ref dict). |
| 184 | * |
| 185 | * Functions List |
| 186 | * -------------- |
| 187 | * - lydict_insert() |
| 188 | * - lydict_insert_zc() |
| 189 | * - lydict_remove() |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 190 | */ |
| 191 | |
| 192 | /** |
| 193 | * @page howtoschemas Schemas |
| 194 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 195 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 196 | * Schema is an internal libyang's representation of a YANG data model. Each schema is connected with |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 197 | * its [context](@ref howtocontext) and loaded using [parser functions](@ref howtoschemasparsers). It means, that |
| 198 | * the schema cannot be created (nor changed) programmatically. In libyang, schemas are used only to |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 199 | * access data model definitions. |
| 200 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 201 | * Schema tree nodes are able to hold private objects (via a pointer to a structure, function, variable, ...) used by |
| 202 | * a caller application. Such an object can be assigned to a specific node using lys_set_private() function. |
| 203 | * Note that the object is not freed by libyang when the context is being destroyed. So the caller is responsible |
| 204 | * for freeing the provided structure after the context is destroyed or the private pointer is set to NULL in |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 205 | * appropriate schema nodes where the object was previously set. This can be automated via destructor function |
| 206 | * to free these private objects. The destructor is passed to the ly_ctx_destroy() function. On the other hand, |
| 207 | * freeing the object while the schema tree is still in use can lead to a segmentation fault. |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 208 | * |
| 209 | * - @subpage howtoschemasparsers |
| 210 | * - @subpage howtoschemasfeatures |
| 211 | * - @subpage howtoschemasprinters |
| 212 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 213 | * \note There are many functions to access information from the schema trees. Details are available in |
| 214 | * the [Schema Tree module](@ref schematree). |
| 215 | * |
Radek Krejci | ee67407 | 2016-09-15 10:37:40 +0200 | [diff] [blame] | 216 | * For information about difference between implemented and imported modules, see the |
| 217 | * [context description](@ref howtocontext). |
| 218 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 219 | * Functions List (not assigned to above subsections) |
| 220 | * -------------------------------------------------- |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 221 | * - lys_getnext() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 222 | * - lys_parent() |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 223 | * - lys_module() |
| 224 | * - lys_node_module() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 225 | * - lys_set_private() |
Radek Krejci | ee67407 | 2016-09-15 10:37:40 +0200 | [diff] [blame] | 226 | * - lys_set_implemented() |
Radek Krejci | 0ec51da | 2016-12-14 16:42:03 +0100 | [diff] [blame] | 227 | * - lys_set_disabled() |
| 228 | * - lys_set_enabled() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 229 | */ |
| 230 | |
| 231 | /** |
| 232 | * @page howtoschemasparsers Parsing Schemas |
| 233 | * |
| 234 | * Schema parser allows to read schema from a specific format. libyang supports the following schema formats: |
| 235 | * |
| 236 | * - YANG |
| 237 | * |
| 238 | * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020). |
| 239 | * Currently, only YANG 1.0 is supported. |
| 240 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 241 | * - YIN |
| 242 | * |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 243 | * Alternative XML-based format to YANG - YANG Independent Notation. The details can be found in |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 244 | * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11). |
| 245 | * |
| 246 | * When the [context](@ref howtocontext) is created, it already contains the following three schemas, which |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 247 | * are implemented internally by libyang: |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 248 | * - ietf-inet-types@2013-07-15 |
| 249 | * - ietf-yang-types@2013-07-15 |
| 250 | * - ietf-yang-library@2015-07-03 |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 251 | * - yang@2016-02-11 |
| 252 | * |
| 253 | * The last one is libyang's internal module to provide namespace for various YANG attributes defined in RFC 6020 |
| 254 | * (such as `insert` attribute for edit-config's data). |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 255 | * |
| 256 | * Other schemas can be added to the context manually as described in [context page](@ref howtocontext) by the functions |
| 257 | * listed below. Besides the schema parser functions, it is also possible to use ly_ctx_load_module() which tries to |
| 258 | * find the required schema automatically - using #ly_module_clb or automatic search in working directory and in the |
| 259 | * context's searchpath. |
| 260 | * |
| 261 | * Functions List |
| 262 | * -------------- |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 263 | * - lys_parse_mem() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 264 | * - lys_parse_fd() |
| 265 | * - lys_parse_path() |
| 266 | * - ly_ctx_set_module_clb() |
| 267 | * - ly_ctx_load_module() |
| 268 | */ |
| 269 | |
| 270 | /** |
| 271 | * @page howtoschemasfeatures YANG Features Manipulation |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 272 | * |
| 273 | * The group of functions prefixed by \b lys_features_ are used to access and manipulate with the schema's |
| 274 | * features. |
| 275 | * |
| 276 | * The first two functions are used to access information about the features in the schema. |
| 277 | * lys_features_list() provides list of all features defined in the specific schema and its |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 278 | * submodules. Optionally, it can also provide information about the state of all features. |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 279 | * Alternatively, caller can use lys_features_state() function to get state of one specific |
| 280 | * feature. |
| 281 | * |
| 282 | * The remaining two functions, lys_features_enable() and lys_features_disable(), are used |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 283 | * to enable and disable the specific feature (or all via the '`*`' value). By default, when the module |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 284 | * is loaded by libyang parser, all features are disabled. |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 285 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 286 | * To get know, if a specific schema node is currently disabled or enable, the lys_is_disabled() function can be used. |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 287 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 288 | * Note, that the feature's state can affect some of the output formats (e.g. Tree format). |
| 289 | * |
| 290 | * Functions List |
| 291 | * -------------- |
| 292 | * - lys_features_list() |
| 293 | * - lys_features_enable() |
| 294 | * - lys_features_disable() |
| 295 | * - lys_features_state() |
| 296 | * - lys_is_disabled() |
| 297 | */ |
| 298 | |
| 299 | /** |
| 300 | * @page howtoschemasprinters Printing Schemas |
| 301 | * |
| 302 | * Schema printers allows to serialize internal representation of a schema module in a specific format. libyang |
| 303 | * supports the following schema formats for printing: |
| 304 | * |
| 305 | * - YANG |
| 306 | * |
| 307 | * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020). |
| 308 | * Currently, only YANG 1.0 is supported. |
| 309 | * |
| 310 | * - YIN |
| 311 | * |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 312 | * Alternative XML-based format to YANG - YANG Independent Notation. The details can be found in |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 313 | * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11). |
| 314 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 315 | * - Tree |
| 316 | * |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 317 | * Simple tree structure of the module where each node is printed as: |
| 318 | * |
| 319 | * <status> <flags> <name> <opts> <type> <if-features> |
| 320 | * |
| 321 | * - `<status>` is one of: |
| 322 | * - `+` for current |
| 323 | * - `x` for deprecated |
| 324 | * - `o` for obsolete |
| 325 | * |
| 326 | * - `<flags>` is one of: |
| 327 | * - `rw` for configuration data |
| 328 | * - `ro` for status data |
| 329 | * - `-x` for RPCs |
| 330 | * - `-n` for Notification |
| 331 | * |
| 332 | * - `<name>` is the name of the node |
| 333 | * - `(<name>)` means that the node is a choice node |
| 334 | * - `:(<name>)` means that the node is a case node |
| 335 | * - if the node is augmented into the tree from another module, it is printed with the module name as |
| 336 | * `<module-name>:<name>`. |
| 337 | * |
| 338 | * - `<opts>` is one of: |
| 339 | * - `?` for an optional leaf or choice |
| 340 | * - `!` for a presence container |
| 341 | * - `*` for a leaf-list or list |
| 342 | * - `[<keys>]` for a list's keys |
| 343 | * |
| 344 | * - `<type>` is the name of the type for leafs and leaf-lists |
| 345 | * - if there is a default value defined, it is printed within angle brackets `<default-value>` |
| 346 | * - if the type is a leafref, the type is printed as -> TARGET` |
| 347 | * |
| 348 | * - `<if-features>` is the list of features this node depends on, printed within curly brackets and |
| 349 | * a question mark `{...}?` |
| 350 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 351 | * |
| 352 | * - Info |
| 353 | * |
| 354 | * Detailed information about the specific node in the schema tree. |
| 355 | * It allows to print information not only about a specific module, but also about its specific part: |
| 356 | * |
| 357 | * - absolute-schema-nodeid |
| 358 | * |
| 359 | * e.g. \a `/modules/module-set-id` in \a `ietf-yang-library` module |
| 360 | * |
| 361 | * - <b>typedef/</b>typedef-name |
| 362 | * |
| 363 | * e.g. \a `typedef/revision-identifier` in \a `ietf-yang-library` module |
| 364 | * |
| 365 | * - <b>feature/</b>feature-name |
| 366 | * |
| 367 | * e.g. \a `feature/ssh` in \a `ietf-netconf-server` module |
| 368 | * |
| 369 | * - <b>grouping/</b>grouping-name/descendant-schema-nodeid |
| 370 | * |
| 371 | * e.g. \a `grouping/module` or \a `grouping/module/module/submodules` in \a `ietf-yang-library` module |
| 372 | * |
| 373 | * - <b>type/</b>leaf-or-leaflist |
| 374 | * |
| 375 | * e.g. \a `type/modules/module-set-id` in \a `ietf-yang-library` module |
| 376 | * |
| 377 | * Printer functions allow to print to the different outputs including a callback function which allows caller |
| 378 | * to have a full control of the output data - libyang passes to the callback a private argument (some internal |
| 379 | * data provided by a caller of lys_print_clb()), string buffer and number of characters to print. Note that the |
| 380 | * callback is supposed to be called multiple times during the lys_print_clb() execution. |
| 381 | * |
| 382 | * Functions List |
| 383 | * -------------- |
| 384 | * - lys_print_mem() |
| 385 | * - lys_print_fd() |
| 386 | * - lys_print_file() |
| 387 | * - lys_print_clb() |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 388 | */ |
| 389 | |
| 390 | /** |
| 391 | * @page howtodata Data Instances |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 392 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 393 | * All data nodes in data trees are connected with their schema node - libyang is not able to represent data of an |
| 394 | * unknown schema. |
| 395 | * |
Michal Vasko | 42aa0ab | 2016-10-25 15:09:32 +0200 | [diff] [blame] | 396 | * Connected to the aforementioned, it is important to mention that there are several kinds of data trees libyang |
| 397 | * can work with. Except for a standard full data tree and configuration data tree, there are trees specific for use |
| 398 | * in NETCONF, which are \<get\> or \<get-config\> replies, \<edit-config\> input content, generic RPC/action request, |
| 399 | * RPC/action reply, or a notification. |
| 400 | * |
| 401 | * Special care is needed when working with action input and RPC/action output, because in these cases the libyang data |
| 402 | * tree does not match the actual data tree NETCONF expects. |
| 403 | * |
| 404 | * <b>Action input</b> differentiates from a standard RPC that the child of \<rpc\> element is not the specific RPC |
| 405 | * request being sent, but a special \<action\> element in the base YANG namespace. It is expected to be present when |
| 406 | * parsing an action input and can optionally be included when the action is printed. |
| 407 | * |
| 408 | * As for <b>RPC output</b>, NETCONF expects the output parameters as direct children of the \<rpc-reply\> element. |
| 409 | * However, libyang encapsulates these parameters in the specific RPC request container. Same as before, it is expected |
| 410 | * to be without this container when parsing and can be printed out. |
| 411 | * |
| 412 | * Lastly, <b>action output</b> is almost similar to RPC output and in NETCONF you actually cannot distinguish them, |
| 413 | * but in case of action output, libyang puts all the output parameters under the action container, which is also |
| 414 | * just a child to all the schema tree ancestors up to the schema top-level, just like in an action input. Same applies |
| 415 | * even in this case, parsed data should be only the output parameters, you can decide how to print it. |
| 416 | * |
| 417 | * So, you do not have to use any special flag when you want to print the data tree the way libyang internally stores |
| 418 | * it, although you will not be able to parse it back, as was mentioned in the paragraphs above. To print data in the |
| 419 | * way NETCONF and libyang expects them to be, use #LYP_NETCONF flag for any printing function. |
| 420 | * |
Michal Vasko | 1ec579e | 2016-09-13 11:24:28 +0200 | [diff] [blame] | 421 | * Please, continue reading a specific subsection or go through all the subsections if you are a new user of libyang. |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 422 | * |
| 423 | * - @subpage howtodataparsers |
| 424 | * - @subpage howtodatamanipulators |
Michal Vasko | 1ec579e | 2016-09-13 11:24:28 +0200 | [diff] [blame] | 425 | * - @subpage howtodatavalidation |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 426 | * - @subpage howtodatawd |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 427 | * - @subpage howtodataprinters |
| 428 | * |
| 429 | * \note API for this group of functions is described in the [Data Instances module](@ref datatree). |
| 430 | * |
| 431 | * Functions List (not assigned to above subsections) |
| 432 | * -------------------------------------------------- |
Michal Vasko | f06fb5b | 2016-09-08 10:05:56 +0200 | [diff] [blame] | 433 | * - lyd_find_instance() |
| 434 | * - lyd_find_xpath() |
Radek Krejci | ae1c3b1 | 2016-09-20 16:30:32 +0200 | [diff] [blame] | 435 | * - lyd_leaf_type() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 436 | */ |
| 437 | |
| 438 | /** |
| 439 | * @page howtodataparsers Parsing Data |
| 440 | * |
| 441 | * Data parser allows to read instances from a specific format. libyang supports the following data formats: |
| 442 | * |
| 443 | * - XML |
| 444 | * |
| 445 | * Original data format used in NETCONF protocol. XML mapping is part of the YANG specification |
| 446 | * ([RFC 6020](http://tools.ietf.org/html/rfc6020)). |
| 447 | * |
| 448 | * - JSON |
| 449 | * |
| 450 | * The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG |
| 451 | * can be found in [this draft](https://tools.ietf.org/html/draft-ietf-netmod-yang-json-05). |
| 452 | * |
| 453 | * Besides the format of input data, the parser functions accepts additional [options](@ref parseroptions) to specify |
| 454 | * how the input data should be processed. |
| 455 | * |
| 456 | * In contrast to the schema parser, data parser also accepts empty input data if such an empty data tree is valid |
| 457 | * according to the schemas in the libyang context. |
| 458 | * |
| 459 | * In case of XML input data, there is one additional way to parse input data. Besides parsing the data from a string |
| 460 | * in memory or a file, caller is able to build an XML tree using [libyang XML parser](@ref howtoxml) and then use |
| 461 | * this tree (or a part of it) as input to the lyd_parse_xml() function. |
| 462 | * |
| 463 | * Functions List |
| 464 | * -------------- |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 465 | * - lyd_parse_mem() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 466 | * - lyd_parse_fd() |
| 467 | * - lyd_parse_path() |
| 468 | * - lyd_parse_xml() |
| 469 | */ |
| 470 | |
| 471 | /** |
| 472 | * @page howtodatamanipulators Manipulating Data |
| 473 | * |
| 474 | * There are many functions to create or modify an existing data tree. You can add new nodes, reconnect nodes from |
| 475 | * one tree to another (or e.g. from one list instance to another) or remove nodes. The functions doesn't allow you |
| 476 | * to put a node to a wrong place (by checking the module), but not all validation checks can be made directly |
| 477 | * (or you have to make a valid change by multiple tree modifications) when the tree is being changed. Therefore, |
Michal Vasko | 58f74f1 | 2016-03-24 13:26:06 +0100 | [diff] [blame] | 478 | * there is lyd_validate() function supposed to be called to make sure that the current data tree is valid. If |
| 479 | * working with RPCs, they are invalid also in case the data nodes are not ordered according to the schema, which |
| 480 | * you can fix easily with lyd_schema_sort(). Note, that not performing validation after some data tree changes |
| 481 | * can cause failure of various libyang functions later. |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 482 | * |
Michal Vasko | 0f14ba6 | 2016-03-21 15:38:11 +0100 | [diff] [blame] | 483 | * Creating data is generally possible in two ways, they can be combined. You can add nodes one-by-one based on |
Michal Vasko | 1ec579e | 2016-09-13 11:24:28 +0200 | [diff] [blame] | 484 | * the node name and/or its parent (lyd_new(), \b lyd_new_anydata_*(), lyd_new_leaf(), and their output variants) or |
Michal Vasko | 58f74f1 | 2016-03-24 13:26:06 +0100 | [diff] [blame] | 485 | * address the nodes using a simple XPath addressing (lyd_new_path()). The latter enables to create a whole path |
| 486 | * of nodes, requires less information about the modified data, and is generally simpler to use. The path format |
| 487 | * specifics can be found [here](@ref howtoxpath). |
Michal Vasko | 0f14ba6 | 2016-03-21 15:38:11 +0100 | [diff] [blame] | 488 | * |
Michal Vasko | 3c12682 | 2016-09-22 13:48:42 +0200 | [diff] [blame] | 489 | * Working with two data subtrees can also be performed two ways. Usually, you would use lyd_insert*() functions. |
| 490 | * They are generally meant for simple inserts of a node into a data tree. For more complicated inserts and when |
| 491 | * merging 2 trees use lyd_merge(). It offers additional options and is basically a more powerful insert. |
Michal Vasko | 45fb282 | 2016-04-18 13:32:17 +0200 | [diff] [blame] | 492 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 493 | * Also remember, that when you are creating/inserting a node, all the objects in that operation must belong to the |
| 494 | * same context. |
| 495 | * |
| 496 | * Modifying the single data tree in multiple threads is not safe. |
| 497 | * |
| 498 | * Functions List |
| 499 | * -------------- |
| 500 | * - lyd_dup() |
| 501 | * - lyd_change_leaf() |
| 502 | * - lyd_insert() |
Radek Krejci | db6b166 | 2016-09-15 10:40:16 +0200 | [diff] [blame] | 503 | * - lyd_insert_sibling() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 504 | * - lyd_insert_before() |
| 505 | * - lyd_insert_after() |
| 506 | * - lyd_insert_attr() |
Michal Vasko | 45fb282 | 2016-04-18 13:32:17 +0200 | [diff] [blame] | 507 | * - lyd_merge() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 508 | * - lyd_new() |
Michal Vasko | 0845b11 | 2016-09-08 10:07:08 +0200 | [diff] [blame] | 509 | * - lyd_new_anydata() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 510 | * - lyd_new_leaf() |
Michal Vasko | f529928 | 2016-03-16 13:32:02 +0100 | [diff] [blame] | 511 | * - lyd_new_path() |
Michal Vasko | 0ba4615 | 2016-05-11 14:16:55 +0200 | [diff] [blame] | 512 | * - lyd_new_output() |
Michal Vasko | 0845b11 | 2016-09-08 10:07:08 +0200 | [diff] [blame] | 513 | * - lyd_new_output_anydata() |
Michal Vasko | 0ba4615 | 2016-05-11 14:16:55 +0200 | [diff] [blame] | 514 | * - lyd_new_output_leaf() |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 515 | * - lyd_schema_sort() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 516 | * - lyd_unlink() |
| 517 | * - lyd_free() |
| 518 | * - lyd_free_attr() |
| 519 | * - lyd_free_withsiblings() |
Michal Vasko | 1ec579e | 2016-09-13 11:24:28 +0200 | [diff] [blame] | 520 | */ |
| 521 | |
| 522 | /** |
| 523 | * @page howtodatavalidation Validating Data |
| 524 | * |
| 525 | * By default, the represented data are supposed to represent a full YANG datastore content. So if a schema declares |
| 526 | * some mandatory nodes, despite configuration or status, the data are supposed to be present in the data tree being |
| 527 | * loaded or validated. However, it is possible to specify other kinds of data (see @ref parseroptions) allowing some |
| 528 | * exceptions to the validation process. |
| 529 | * |
| 530 | * Data validation is performed implicitly to the input data processed by the parser (\b lyd_parse_*() functions) and |
| 531 | * on demand via the lyd_validate() function. The lyd_validate() is supposed to be used when a (complex or simple) |
| 532 | * change is done on the data tree (via a combination of \b lyd_change_*(), \b lyd_insert*(), \b lyd_new*(), |
| 533 | * lyd_unlink() and lyd_free() functions). |
| 534 | * |
| 535 | * Must And When Conditions Accessible Tree |
| 536 | * ---------------------------------------- |
| 537 | * |
| 538 | * In YANG 1.1, there can be \b must and/or \b when expressions in RPC/action input or output, or in notifications that |
| 539 | * require access to the configuration datastore and/or state data. Normally, when working with any of the aforementioned |
| 540 | * data trees, they must contain only the RPC/action/notification itself, without any additional configuration or state |
| 541 | * data. So how can then these conditions be verified during validation? |
| 542 | * |
| 543 | * There is an option to pass this additional data tree to all the functions that perform \b must and \b when condition |
Michal Vasko | 3c4cf90 | 2017-01-03 14:43:38 +0100 | [diff] [blame^] | 544 | * checking (\b lyd_parse_*() and lyd_validate()). Also, there are 2 flags of \b struct lys_node that |
| 545 | * mark schema nodes that include paths that require foreign nodes (outside their subtree) for their evaluation. #LYS_XPATH_DEP |
| 546 | * marks nodes with such must and/or when expressions, #LYS_LEAFREF_DEP with such a leafref. |
Michal Vasko | 1ec579e | 2016-09-13 11:24:28 +0200 | [diff] [blame] | 547 | * The subtree root is always the particular operation data node (for RPC it is the RPC data node and all |
| 548 | * the input or output nodes as its children and similarly for action and notification). Note that for action and |
| 549 | * not-top-level notification this means that all their parents are not considered as belonging to their subtree even though |
| 550 | * they are included in their data tree and must be present for the operation validation to pass. The reason for this is that if |
| 551 | * there are any lists in those parents, we cannot know if there are not some other instances of them in the standard |
| 552 | * data tree in addition to the one used in the action/notification invocation. |
| 553 | * |
| 554 | * There were 2 ways of using this mechanism envisioned (explained below), but you can combine or modify them. |
| 555 | * |
| 556 | * ### Fine-grained Data Retrieval ### |
| 557 | * |
| 558 | * This approach is recommended when you do not maintain a full configuration data tree with state data at all times. |
| 559 | * |
| 560 | * Firstly, you should somehow learn that the operation data tree you are currently working with includes some schema |
| 561 | * node instances that have conditions that require foreign data. You can either know this about every operation beforehand |
Michal Vasko | 3c4cf90 | 2017-01-03 14:43:38 +0100 | [diff] [blame^] | 562 | * or you go through all the schema nodes looking for the flags #LYS_XPATH_DEP and #LYS_LEAFREF_DEP. Then you should use lys_node_xpath_atomize() |
Michal Vasko | 1ec579e | 2016-09-13 11:24:28 +0200 | [diff] [blame] | 563 | * to retrieve all XPath condition dependencies (in the form of schema nodes) outside the operation subtree. You will likely |
| 564 | * want to use the flag #LYXP_NO_LOCAL to get rid of all the nodes from inside the subtree (you should already have those). |
| 565 | * 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() |
| 566 | * (it will be expected). Then you pass this tree to the validation and it should now have access to all the nodes that |
| 567 | * can potentially affect the XPath evaluation and no other. |
| 568 | * |
| 569 | * ### Maintaining Configuration And State Data Tree ### |
| 570 | * |
| 571 | * If you have a full data tree with state data available for the validation process then it is quite simple (compared |
| 572 | * to the first approach). You can simply always pass it to validation of these operations and in cases it is not required |
| 573 | * (no nodes with conditions traversing foreign nodes) only a negligible amount of redundant work is performed and you can |
| 574 | * skip the process of learning whether it is required or not. |
| 575 | * |
| 576 | * Functions List |
| 577 | * -------------- |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 578 | * - lyd_validate() |
| 579 | */ |
| 580 | |
| 581 | /** |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 582 | * @page howtodatawd Default Values |
| 583 | * |
Radek Krejci | db6b166 | 2016-09-15 10:40:16 +0200 | [diff] [blame] | 584 | * libyang provides support for work with default values as defined in [RFC 6243](https://tools.ietf.org/html/rfc6243). |
Radek Krejci | 46180b5 | 2016-08-31 16:01:32 +0200 | [diff] [blame] | 585 | * This document defines 4 modes for handling default nodes in a data tree, libyang adds the fifth mode: |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 586 | * - \b explicit - Only the explicitly set configuration data. But in the case of status data, missing default |
Radek Krejci | 46180b5 | 2016-08-31 16:01:32 +0200 | [diff] [blame] | 587 | * data are added into the tree. In libyang, this mode is represented by #LYP_WD_EXPLICIT option. |
| 588 | * - \b trim - Data nodes containing the schema default value are removed. This mode is applied using #LYP_WD_TRIM option. |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 589 | * - \b report-all - All the missing default data are added into the data tree. This mode is represented by |
Radek Krejci | 46180b5 | 2016-08-31 16:01:32 +0200 | [diff] [blame] | 590 | * #LYP_WD_ALL option. |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 591 | * - \b report-all-tagged - In this case, all the missing default data are added as in case of the `report-all` mode, |
| 592 | * but additionally all the nodes (existing as well as added) containing the schema default value |
Radek Krejci | 46180b5 | 2016-08-31 16:01:32 +0200 | [diff] [blame] | 593 | * are tagged (see the note below). libyang uses #LYP_WD_ALL_TAG option for this mode. |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 594 | * - \b report-implicit-tagged - The last mode is similar to the previous one, except only the added nodes are tagged. |
Radek Krejci | 46180b5 | 2016-08-31 16:01:32 +0200 | [diff] [blame] | 595 | * This is the libyang's extension and it is represented by #LYP_WD_IMPL_TAG option. |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 596 | * |
Radek Krejci | 46180b5 | 2016-08-31 16:01:32 +0200 | [diff] [blame] | 597 | * libyang automatically adds/maintain the default nodes when a data tree is being parsed or validated. Note, that in a |
| 598 | * modified data tree (via e.g. lys_insert() or lys_free()), some of the default nodes can be missing or they can be |
| 599 | * present by mistake. Such a data tree is again corrected during the next lyd_validate() call. |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 600 | * |
Radek Krejci | 46180b5 | 2016-08-31 16:01:32 +0200 | [diff] [blame] | 601 | * The implicit (default) nodes, created by libyang, are marked with the ::lyd_node#dflt flag which applies to the |
Radek Krejci | d3cfbc9 | 2016-09-15 10:39:33 +0200 | [diff] [blame] | 602 | * leafs and leaf-lists. In case of containers, the flag means that the container holds only a default node(s) or it |
| 603 | * is an empty container (according to YANG 1.1 spec, all such containers are part of the accessible data tree). |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 604 | * |
Radek Krejci | 46180b5 | 2016-08-31 16:01:32 +0200 | [diff] [blame] | 605 | * The presence of the default nodes during the data tree lifetime is affected by the LYD_OPT_ flag used to |
| 606 | * parse/validate the tree: |
| 607 | * - #LYD_OPT_DATA - all the default nodes are present despite they are configuration or status nodes |
| 608 | * - #LYD_OPT_CONFIG - only the configuration data nodes are added into the tree |
| 609 | * - #LYD_OPT_GET, #LYD_OPT_GETCONFIG, #LYD_OPT_EDIT - no default nodes are added |
| 610 | * - #LYD_OPT_RPC, #LYD_OPT_RPCREPLY, #LYD_OPT_NOTIF - the default nodes from the particular subtree are added |
| 611 | * |
Radek Krejci | db6b166 | 2016-09-15 10:40:16 +0200 | [diff] [blame] | 612 | * The with-default modes described above are supported when the data tree is being printed with the |
Radek Krejci | 46180b5 | 2016-08-31 16:01:32 +0200 | [diff] [blame] | 613 | * [LYP_WD_ printer flags](@ref printerflags). Note, that in case of #LYP_WD_ALL_TAG and #LYP_WD_IMPL_TAG modes, |
| 614 | * the XML/JSON attributes are printed only if the context includes the ietf-netconf-with-defaults schema. Otherwise, |
Radek Krejci | d3cfbc9 | 2016-09-15 10:39:33 +0200 | [diff] [blame] | 615 | * these modes have the same result as #LYP_WD_ALL. The presence of empty containers (despite they were added explicitly |
| 616 | * or implicitly as part of accessible data tree) depends on #LYP_KEEPEMPTYCONT option. |
Radek Krejci | 46180b5 | 2016-08-31 16:01:32 +0200 | [diff] [blame] | 617 | * |
| 618 | * To get know if the particular leaf or leaf-list node contains default value (despite implicit or explicit), you can |
Radek Krejci | db6b166 | 2016-09-15 10:40:16 +0200 | [diff] [blame] | 619 | * use lyd_wd_default() function. |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 620 | * |
| 621 | * Functions List |
| 622 | * -------------- |
Radek Krejci | 46180b5 | 2016-08-31 16:01:32 +0200 | [diff] [blame] | 623 | * - lyd_wd_default() |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 624 | * |
| 625 | * - lyd_parse_mem() |
| 626 | * - lyd_parse_fd() |
| 627 | * - lyd_parse_path() |
| 628 | * - lyd_parse_xml() |
| 629 | * - lyd_validate() |
Radek Krejci | 46180b5 | 2016-08-31 16:01:32 +0200 | [diff] [blame] | 630 | * - lyd_print_mem() |
| 631 | * - lyd_print_fd() |
| 632 | * - lyd_print_file() |
| 633 | * - lyd_print_clb() |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 634 | */ |
| 635 | |
| 636 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 637 | * @page howtodataprinters Printing Data |
| 638 | * |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 639 | * Data printers allows to serialize internal representation of a data tree in a specific format. libyang |
| 640 | * supports the following data formats for printing: |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 641 | * |
| 642 | * - XML |
| 643 | * |
| 644 | * Basic format as specified in rules of mapping YANG modeled data to XML in |
| 645 | * [RFC 6020](http://tools.ietf.org/html/rfc6020). It is possible to specify if |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 646 | * the indentation (formatting) will be used (by #LYP_FORMAT @ref printerflags "printer option"). |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 647 | * |
| 648 | * - JSON |
| 649 | * |
| 650 | * The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG |
Radek Krejci | f6ab2cd | 2016-04-18 17:15:26 +0200 | [diff] [blame] | 651 | * can be found in [this draft](https://tools.ietf.org/html/draft-ietf-netmod-yang-json-05).It is possible to specify |
| 652 | * if the indentation (formatting) will be used (by #LYP_FORMAT @ref printerflags "printer option"). |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 653 | * |
| 654 | * Printer functions allow to print to the different outputs including a callback function which allows caller |
| 655 | * to have a full control of the output data - libyang passes to the callback a private argument (some internal |
| 656 | * data provided by a caller of lyd_print_clb()), string buffer and number of characters to print. Note that the |
| 657 | * callback is supposed to be called multiple times during the lyd_print_clb() execution. |
| 658 | * |
Radek Krejci | 46180b5 | 2016-08-31 16:01:32 +0200 | [diff] [blame] | 659 | * To print the data tree with default nodes according to the with-defaults capability defined in |
| 660 | * [RFC 6243](https://tools.ietf.org/html/rfc6243), check the [page about the default values](@ref howtodatawd). |
| 661 | * |
Michal Vasko | 42aa0ab | 2016-10-25 15:09:32 +0200 | [diff] [blame] | 662 | * Also, to print the data in NETCONF format, use the #LYP_NETCONF flag. More information can be found on the page |
| 663 | * @ref howtodata. |
| 664 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 665 | * Functions List |
| 666 | * -------------- |
| 667 | * - lyd_print_mem() |
| 668 | * - lyd_print_fd() |
| 669 | * - lyd_print_file() |
| 670 | * - lyd_print_clb() |
| 671 | */ |
| 672 | |
| 673 | /** |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 674 | * @page howtoxpath XPath Addressing |
| 675 | * |
| 676 | * Internally, XPath evaluation is performed on \b when and \b must conditions in the schema. For that almost |
Michal Vasko | 88aae04 | 2016-09-08 08:57:09 +0200 | [diff] [blame] | 677 | * a full XPath 1.0 evaluator was implemented except that only node sets are returned. This XPath implementation |
Michal Vasko | f06fb5b | 2016-09-08 10:05:56 +0200 | [diff] [blame] | 678 | * is available on data trees by calling lyd_find_xpath() and on schema trees by calling lys_find_xpath(). |
Michal Vasko | 46a4bf9 | 2016-09-08 08:23:49 +0200 | [diff] [blame] | 679 | * This XPath conforms to the YANG specification (RFC 6020 section 6.4). Some useful examples: |
Michal Vasko | 8e62769 | 2016-04-19 12:15:47 +0200 | [diff] [blame] | 680 | * |
Michal Vasko | ebea701 | 2016-04-19 14:15:22 +0200 | [diff] [blame] | 681 | * - get all top-level nodes of the __module-name__ |
| 682 | * |
| 683 | * /module-name:* |
| 684 | * |
| 685 | * - get all the descendants of __container__ (excluding __container__) |
| 686 | * |
| 687 | * /module-name:container//\asterisk |
| 688 | * |
| 689 | * - 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__) |
| 690 | * |
| 691 | * /module-name:container/list[key1='1'][key2='2'] |
| 692 | * |
| 693 | * - get __leaf-list__ instance with the value __val__ |
| 694 | * |
| 695 | * /module-name:container/leaf-list[.='val'] |
| 696 | * |
| 697 | * - get __aug-leaf__, which was added to __module-name__ from an augment module __augment-module__ |
| 698 | * |
| 699 | * /module-name:container/container2/augment-module:aug-cont/aug-leaf |
| 700 | * |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 701 | * |
| 702 | * A very small subset of this full XPath is recognized by lyd_new_path(). Basically, only a relative or absolute |
| 703 | * path can be specified to identify a new data node. However, lists must be identified by all their keys and created |
| 704 | * with all of them, so for those cases predicates are allowed. Predicates must be ordered the way the keys are ordered |
Michal Vasko | 1acf850 | 2016-05-05 09:14:07 +0200 | [diff] [blame] | 705 | * and all the keys must be specified. Every predicate includes a single key with its value. Optionally, leaves and |
| 706 | * leaf-lists can have predicates specifying their value in the path itself. All these paths are valid XPath |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 707 | * expressions. Example: |
| 708 | * |
Michal Vasko | 1acf850 | 2016-05-05 09:14:07 +0200 | [diff] [blame] | 709 | * /ietf-yang-library:modules-state/module[name='ietf-yang-library'][revision='']/conformance[.='implement'] |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 710 | * |
| 711 | * Almost the same XPath is accepted by ly_ctx_get_node(). The difference is that it is not used on data, but schema, |
| 712 | * which means there are no key values and only one node matches one path. In effect, lists do not have to have any |
| 713 | * predicates. If they do, they do not need to have all the keys specified and if values are included, they are ignored. |
| 714 | * Nevertheless, any such expression is still a valid XPath, but can return more nodes if executed on a data tree. |
| 715 | * Examples (all returning the same node): |
| 716 | * |
| 717 | * /ietf-yang-library:modules-state/module/submodules |
| 718 | * /ietf-yang-library:modules-state/module[name]/submodules |
| 719 | * /ietf-yang-library:modules-state/module[name][revision]/submodules |
| 720 | * /ietf-yang-library:modules-state/module[name='ietf-yang-library'][revision]/submodules |
| 721 | * |
| 722 | * Also, `choice`, `case`, `input`, and `output` nodes need to be specified and cannot be skipped in schema XPaths. Use |
Michal Vasko | 8d26e5c | 2016-09-08 10:03:49 +0200 | [diff] [blame] | 723 | * lys_find_xpath() if you want to search based on a data XPath. |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 724 | * |
| 725 | * Also note, that in all cases the node's prefix is specified as the name of the appropriate YANG schema. Any node |
| 726 | * can be prefixed by the module name. However, if the prefix is omitted, the module name is inherited from the previous |
| 727 | * (parent) node. It means, that the first node in the path is always supposed to have a prefix. |
| 728 | * |
| 729 | * Functions List |
| 730 | * -------------- |
Michal Vasko | f06fb5b | 2016-09-08 10:05:56 +0200 | [diff] [blame] | 731 | * - lyd_find_xpath() |
| 732 | * - lys_find_xpath() |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 733 | * - lyd_new_path() |
| 734 | * - ly_ctx_get_node() |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 735 | */ |
| 736 | |
| 737 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 738 | * @page howtoxml libyang XML Support |
| 739 | * |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 740 | * libyang XML parser is able to parse XML documents. The main purpose is to load data modeled by YANG. However, it can |
| 741 | * be used as a standalone XML parser with the following limitations in comparison to a full-featured XML parsers: |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 742 | * - comments are ignored |
| 743 | * - Doctype declaration is ignored |
| 744 | * - CData sections are ignored |
| 745 | * - Process Instructions (PI) are ignored |
| 746 | * |
| 747 | * The API is designed to almost only read-only access. You can simply load XML document, go through the tree as |
| 748 | * you wish and dump the tree to an output. The only "write" functions are lyxml_free() and lyxml_unlink() to remove |
| 749 | * part of the tree or to unlink (separate) a subtree. |
| 750 | * |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 751 | * XML parser is used internally by libyang for parsing YIN schemas and data instances in XML format. |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 752 | * |
| 753 | * \note API for this group of functions is described in the [XML Parser module](@ref xmlparser). |
| 754 | * |
| 755 | * Functions List |
| 756 | * -------------- |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 757 | * - lyxml_parse_mem() |
| 758 | * - lyxml_parse_path() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 759 | * - lyxml_get_attr() |
| 760 | * - lyxml_get_ns() |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 761 | * - lyxml_print_mem() |
| 762 | * - lyxml_print_fd() |
| 763 | * - lyxml_print_file() |
| 764 | * - lyxml_print_clb() |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 765 | * - lyxml_unlink() |
| 766 | * - lyxml_free() |
| 767 | */ |
| 768 | |
| 769 | /** |
| 770 | * @page howtothreads libyang in Threads |
| 771 | * |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 772 | * libyang can be used in multithreaded applications keeping in mind the following rules: |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 773 | * - libyang context manipulation (adding new schemas) is not thread safe and it is supposed to be done in a main |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 774 | * thread before any other work with context, schemas or data instances. Destroying the context is supposed to |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 775 | * be done when no other thread accesses context, schemas nor data trees |
| 776 | * - Data parser (\b lyd_parse*() functions) can be used simultaneously in multiple threads (also the returned |
| 777 | * #ly_errno is thread safe). |
| 778 | * - Modifying (lyd_new(), lyd_insert(), lyd_unlink(), lyd_free() and many other functions) a single data tree is not |
| 779 | * thread safe. |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 780 | */ |
Radek Krejci | 94ca54b | 2015-07-08 15:48:47 +0200 | [diff] [blame] | 781 | |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 782 | /** |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 783 | * |
| 784 | * @page howtologger Logger |
| 785 | * |
| 786 | * There are 4 verbosity levels defined as ::LY_LOG_LEVEL. The level can be |
| 787 | * changed by the ly_verb() function. By default, the verbosity level is |
| 788 | * set to #LY_LLERR value. |
| 789 | * |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 790 | * When an error is encountered, the error message and error number are stored for |
| 791 | * later use. Caller is able to access the last error message via ly_errmsg() and the |
| 792 | * corresponding last error code via #ly_errno. If that was a validation error (#ly_errno |
| 793 | * is set to #LY_EVALID), also validation error code (via #ly_vecode) and path to the |
| 794 | * error node (via ly_errpath()) are available. |
| 795 | * |
| 796 | * For some specific cases, a YANG schema can define error message and/or error tag (mainly for |
Michal Vasko | ebea701 | 2016-04-19 14:15:22 +0200 | [diff] [blame] | 797 | * use in NETCONF). If a message is set, it is provided via ly_errmsg(). If a tag is set in schema, |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 798 | * it is available via ly_erraptag() (if not set, the returned string is empty). |
| 799 | * |
Michal Vasko | ebea701 | 2016-04-19 14:15:22 +0200 | [diff] [blame] | 800 | * By default, all libyang messages are printed to `stderr`. However, the caller is able to set their own logging |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 801 | * callback function. In that case, instead of printing messages, libyang passes error level, message and path |
| 802 | * (if any) to the caller's callback function. In case of error level, the message and path are still |
| 803 | * automatically stored and available via the functions and macros described above. |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 804 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 805 | * \note API for this group of functions is described in the [logger module](@ref logger). |
| 806 | * |
| 807 | * Functions List |
| 808 | * -------------- |
| 809 | * - ly_verb() |
| 810 | * - ly_set_log_clb() |
| 811 | * - ly_get_log_clb() |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 812 | * - ly_errmsg() |
| 813 | * - ly_errpath() |
| 814 | * - ly_errapptag() |
| 815 | * - #ly_errno |
| 816 | * - #ly_vecode |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 817 | */ |
| 818 | |
| 819 | /** |
| 820 | * @defgroup context Context |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 821 | * @{ |
| 822 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 823 | * Structures and functions to manipulate with the libyang "containers". The \em context concept allows callers |
| 824 | * to work in environments with different sets of YANG schemas. More detailed information can be found at |
| 825 | * @ref howtocontext page. |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 826 | */ |
| 827 | |
| 828 | /** |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 829 | * @brief libyang context handler. |
| 830 | */ |
| 831 | struct ly_ctx; |
| 832 | |
| 833 | /** |
| 834 | * @brief Create libyang context |
| 835 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 836 | * Context is used to hold all information about schemas. Usually, the application is supposed |
Radek Krejci | 91b833c | 2015-09-04 11:49:43 +0200 | [diff] [blame] | 837 | * to work with a single context in which libyang is holding all schemas (and other internal |
| 838 | * information) according to which the data trees will be processed and validated. So, the schema |
| 839 | * trees are tightly connected with the specific context and they are held by the context internally |
| 840 | * - caller does not need to keep pointers to the schemas returned by lys_parse(), context knows |
| 841 | * about them. The data trees created with lyd_parse() are still connected with the specific context, |
| 842 | * but they are not internally held by the context. The data tree just points and lean on some data |
| 843 | * held by the context (schema tree, string dictionary, etc.). Therefore, in case of data trees, caller |
| 844 | * is supposed to keep pointers returned by the lyd_parse() and manage the data tree on its own. This |
| 845 | * also affects the number of instances of both tree types. While you can have only one instance of |
| 846 | * specific schema connected with a single context, number of data tree instances is not connected. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 847 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 848 | * @param[in] search_dir Directory where libyang will search for the imported or included modules |
| 849 | * and submodules. If no such directory is available, NULL is accepted. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 850 | * |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 851 | * @return Pointer to the created libyang context, NULL in case of error. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 852 | */ |
| 853 | struct ly_ctx *ly_ctx_new(const char *search_dir); |
| 854 | |
| 855 | /** |
Michal Vasko | 60ba9a6 | 2015-07-03 14:42:31 +0200 | [diff] [blame] | 856 | * @brief Change the search path in libyang context |
| 857 | * |
| 858 | * @param[in] ctx Context to be modified. |
| 859 | * @param[in] search_dir New search path to replace the current one in ctx. |
| 860 | */ |
| 861 | void ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir); |
| 862 | |
| 863 | /** |
Radek Krejci | 5a79757 | 2015-10-21 15:45:45 +0200 | [diff] [blame] | 864 | * @brief Get current value of the search path in libyang context |
| 865 | * |
| 866 | * @param[in] ctx Context to query. |
| 867 | * @return Current value of the search path. |
| 868 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 869 | const char *ly_ctx_get_searchdir(const struct ly_ctx *ctx); |
Radek Krejci | 5a79757 | 2015-10-21 15:45:45 +0200 | [diff] [blame] | 870 | |
| 871 | /** |
Radek Krejci | 7ab2515 | 2015-08-07 14:48:45 +0200 | [diff] [blame] | 872 | * @brief Get data of an internal ietf-yang-library module. |
| 873 | * |
| 874 | * @param[in] ctx Context with the modules. |
| 875 | * @return Root data node corresponding to the model, NULL on error. |
| 876 | * Caller is responsible for freeing the returned data tree using lyd_free(). |
| 877 | */ |
| 878 | struct lyd_node *ly_ctx_info(struct ly_ctx *ctx); |
| 879 | |
| 880 | /** |
Radek Krejci | 0ec51da | 2016-12-14 16:42:03 +0100 | [diff] [blame] | 881 | * @brief Iterate over all (enabled) modules in a context. |
Michal Vasko | d7957c0 | 2016-04-01 10:27:26 +0200 | [diff] [blame] | 882 | * |
| 883 | * @param[in] ctx Context with the modules. |
| 884 | * @param[in,out] idx Index of the next module to be returned. Value of 0 starts from the beginning. |
| 885 | * @return Next context module, NULL if the last was already returned. |
| 886 | */ |
| 887 | const struct lys_module *ly_ctx_get_module_iter(const struct ly_ctx *ctx, uint32_t *idx); |
| 888 | |
| 889 | /** |
Radek Krejci | 0ec51da | 2016-12-14 16:42:03 +0100 | [diff] [blame] | 890 | * @brief Iterate over the disabled modules in a context. |
| 891 | * |
| 892 | * @param[in] ctx Context with the modules. |
| 893 | * @param[in,out] idx Index of the next module to be returned. Value of 0 starts from the beginning. |
| 894 | * @return Next context module, NULL if the last was already returned. |
| 895 | */ |
| 896 | const struct lys_module *ly_ctx_get_disabled_module_iter(const struct ly_ctx *ctx, uint32_t *idx); |
| 897 | |
| 898 | /** |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 899 | * @brief Get pointer to the schema tree of the module of the specified name. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 900 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 901 | * @param[in] ctx Context to work in. |
| 902 | * @param[in] name Name of the YANG module to get. |
Radek Krejci | f647e61 | 2015-07-30 11:36:07 +0200 | [diff] [blame] | 903 | * @param[in] revision Optional revision date of the YANG module to get. If not specified, |
| 904 | * the schema in the newest revision is returned if any. |
| 905 | * @return Pointer to the data model structure, NULL if no schema following the name and |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 906 | * revision requirements is present in the context. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 907 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 908 | const struct lys_module *ly_ctx_get_module(const struct ly_ctx *ctx, const char *name, const char *revision); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 909 | |
| 910 | /** |
Radek Krejci | 21601a3 | 2016-03-07 11:39:27 +0100 | [diff] [blame] | 911 | * @brief Get pointer to the older schema tree to the specified one in the provided context. |
| 912 | * |
| 913 | * The module is not necessarily from the provided \p ctx. If there are multiple schemas older than the |
| 914 | * provided one, the newest of them is returned. |
| 915 | * |
| 916 | * The function can be used in combination with ly_ctx_get_module() to get all revisions of a module in a context: |
| 917 | * \code{.c} |
| 918 | * for (mod = ly_ctx_get_module(ctx, name, NULL); mod; mod = ly_ctx_get_module_older(ctx, mod)) { |
| 919 | * ... |
| 920 | * } |
| 921 | * \endcode |
| 922 | * |
| 923 | * @param[in] ctx Context to work in. |
| 924 | * @param[in] module YANG module to compare with |
| 925 | * @return Pointer to the data model structure, NULL if no older schema is present in the context. |
| 926 | */ |
| 927 | const struct lys_module *ly_ctx_get_module_older(const struct ly_ctx *ctx, const struct lys_module *module); |
| 928 | |
| 929 | /** |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 930 | * @brief Try to find the model in the searchpath of \p ctx and load it into it. If custom missing |
| 931 | * module callback is set, it is used instead. |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 932 | * |
Radek Krejci | 31fb8be | 2016-06-23 15:26:26 +0200 | [diff] [blame] | 933 | * If there is a possibility that the requested module is already in the context, you should call |
| 934 | * the ly_ctx_get_module() first to avoid a lot of work performed by ly_ctx_load_module(). |
| 935 | * |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 936 | * @param[in] ctx Context to add to. |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 937 | * @param[in] name Name of the module to load. |
| 938 | * @param[in] revision Optional revision date of the module. If not specified, it is |
| 939 | * assumed that there is only one model revision in the searchpath (the first matching file |
| 940 | * is parsed). |
| 941 | * @return Pointer to the data model structure, NULL if not found or some error occured. |
| 942 | */ |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 943 | const struct lys_module *ly_ctx_load_module(struct ly_ctx *ctx, const char *name, const char *revision); |
| 944 | |
| 945 | /** |
| 946 | * @brief Callback for retrieving missing included or imported models in a custom way. |
| 947 | * |
Michal Vasko | 8447515 | 2016-07-25 16:16:25 +0200 | [diff] [blame] | 948 | * @param[in] mod_name Missing module name. |
| 949 | * @param[in] mod_rev Optional missing module revision. |
| 950 | * @param[in] submod_name Optional missing submodule name. |
| 951 | * @param[in] submod_rev Optional missing submodule revision. |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 952 | * @param[in] user_data User-supplied callback data. |
| 953 | * @param[out] format Format of the returned module data. |
Michal Vasko | 880dceb | 2016-03-03 15:44:56 +0100 | [diff] [blame] | 954 | * @param[out] free_module_data Callback for freeing the returned module data. If not set, the data will be left untouched. |
Radek Krejci | 31fb8be | 2016-06-23 15:26:26 +0200 | [diff] [blame] | 955 | * @return Requested module data or NULL if the callback is not able to provide the requested schema content for any reason. |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 956 | */ |
Michal Vasko | 8447515 | 2016-07-25 16:16:25 +0200 | [diff] [blame] | 957 | typedef char *(*ly_module_clb)(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev, |
| 958 | void *user_data, LYS_INFORMAT *format, void (**free_module_data)(void *model_data)); |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 959 | |
| 960 | /** |
Michal Vasko | 98b5f95 | 2016-10-26 12:14:40 +0200 | [diff] [blame] | 961 | * @brief Set missing include or import module callback. It is meant to be used when the models |
| 962 | * are not locally available (such as when downloading modules from a NETCONF server), it should |
| 963 | * not be required in other cases. |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 964 | * |
| 965 | * @param[in] ctx Context that will use this callback. |
| 966 | * @param[in] clb Callback responsible for returning a missing model. |
| 967 | * @param[in] user_data Arbitrary data that will always be passed to the callback \p clb. |
| 968 | */ |
| 969 | void ly_ctx_set_module_clb(struct ly_ctx *ctx, ly_module_clb clb, void *user_data); |
| 970 | |
| 971 | /** |
| 972 | * @brief Get the custom callback for missing module retrieval. |
| 973 | * |
| 974 | * @param[in] ctx Context to read from. |
| 975 | * @param[in] user_data Optional pointer for getting the user-supplied callbck data. |
| 976 | * @return Custom user missing module callback or NULL if not set. |
| 977 | */ |
| 978 | ly_module_clb ly_ctx_get_module_clb(const struct ly_ctx *ctx, void **user_data); |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 979 | |
| 980 | /** |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 981 | * @brief Get pointer to the schema tree of the module of the specified namespace |
| 982 | * |
| 983 | * @param[in] ctx Context to work in. |
| 984 | * @param[in] ns Namespace of the YANG module to get. |
| 985 | * @param[in] revision Optional revision date of the YANG module to get. If not specified, |
| 986 | * the schema in the newest revision is returned if any. |
| 987 | * @return Pointer to the data model structure, NULL if no schema following the namespace and |
| 988 | * revision requirements is present in the context. |
| 989 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 990 | const struct lys_module *ly_ctx_get_module_by_ns(const struct ly_ctx *ctx, const char *ns, const char *revision); |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 991 | |
| 992 | /** |
Radek Krejci | 62f0da7 | 2016-03-07 11:35:43 +0100 | [diff] [blame] | 993 | * @brief Get submodule of a main module. |
| 994 | * |
| 995 | * If you already have the pointer to the submodule's main module, use ly_ctx_get_submodule2() instead. |
Michal Vasko | 7bf0688 | 2015-07-03 15:33:56 +0200 | [diff] [blame] | 996 | * |
Radek Krejci | a7533f2 | 2016-03-07 07:37:45 +0100 | [diff] [blame] | 997 | * @param[in] ctx Context to work in. |
Michal Vasko | f6d94c6 | 2016-04-05 11:21:54 +0200 | [diff] [blame] | 998 | * @param[in] module Name of the main (belongs-to) module. If NULL, all module submodules are searched. |
| 999 | * @param[in] revision Optional revision date of \p module. If NULL, all revisions of \p module |
| 1000 | * are searched. If set, \p module must also be set. |
Radek Krejci | a7533f2 | 2016-03-07 07:37:45 +0100 | [diff] [blame] | 1001 | * @param[in] submodule Name of the submodule to get. |
Michal Vasko | f6d94c6 | 2016-04-05 11:21:54 +0200 | [diff] [blame] | 1002 | * @param[in] sub_revision Optional revision date of \p submodule. If NULL, the newest revision of \p submodule |
| 1003 | * is returned. |
Michal Vasko | 7bf0688 | 2015-07-03 15:33:56 +0200 | [diff] [blame] | 1004 | * @return Pointer to the data model structure. |
| 1005 | */ |
Radek Krejci | a7533f2 | 2016-03-07 07:37:45 +0100 | [diff] [blame] | 1006 | const struct lys_submodule *ly_ctx_get_submodule(const struct ly_ctx *ctx, const char *module, const char *revision, |
Michal Vasko | f6d94c6 | 2016-04-05 11:21:54 +0200 | [diff] [blame] | 1007 | const char *submodule, const char *sub_revision); |
Michal Vasko | 7bf0688 | 2015-07-03 15:33:56 +0200 | [diff] [blame] | 1008 | |
| 1009 | /** |
Radek Krejci | 62f0da7 | 2016-03-07 11:35:43 +0100 | [diff] [blame] | 1010 | * @brief Get submodule of a main module. |
| 1011 | * |
| 1012 | * If you have only the name (and optionally revision) of the submodule's main module, use ly_ctx_get_submodule() |
| 1013 | * instead. |
| 1014 | * |
| 1015 | * @param[in] main_module Main module (belongs to) of the searched submodule. |
| 1016 | * @param[in] submodule Name of the submodule to get. |
| 1017 | * @return Pointer to the data model structure. |
| 1018 | */ |
| 1019 | const struct lys_submodule *ly_ctx_get_submodule2(const struct lys_module *main_module, const char *submodule); |
| 1020 | |
| 1021 | /** |
Michal Vasko | 3547c53 | 2016-03-14 09:40:50 +0100 | [diff] [blame] | 1022 | * @brief Get schema node according to the given schema node identifier in JSON format. |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 1023 | * |
Michal Vasko | 3547c53 | 2016-03-14 09:40:50 +0100 | [diff] [blame] | 1024 | * If the \p nodeid is absolute, the first node identifier must be prefixed with |
| 1025 | * the module name. Then every other identifier either has an explicit module name or |
| 1026 | * the module name of the previous node is assumed. Examples: |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 1027 | * |
| 1028 | * /ietf-netconf-monitoring:get-schema/input/identifier |
| 1029 | * /ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address/ip |
| 1030 | * |
Michal Vasko | 3547c53 | 2016-03-14 09:40:50 +0100 | [diff] [blame] | 1031 | * If the \p nodeid is relative, \p start is mandatory and is the starting point |
| 1032 | * for the resolution. The first node identifier does not need a module name. |
| 1033 | * |
Michal Vasko | 7b54f7e | 2016-05-03 15:07:31 +0200 | [diff] [blame] | 1034 | * Predicates on lists are accepted (ignored) in the form of "<key>(=<value>)" |
| 1035 | * and on leaves/leaf-lists ".(=<value>)". |
| 1036 | * |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 1037 | * @param[in] ctx Context to work in. |
Michal Vasko | 3547c53 | 2016-03-14 09:40:50 +0100 | [diff] [blame] | 1038 | * @param[in] start Starting node for a relative schema node identifier, in which |
| 1039 | * case it is mandatory. |
| 1040 | * @param[in] nodeid JSON schema node identifier. |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 1041 | * @return Resolved schema node or NULL. |
| 1042 | */ |
Michal Vasko | 3547c53 | 2016-03-14 09:40:50 +0100 | [diff] [blame] | 1043 | const struct lys_node *ly_ctx_get_node(struct ly_ctx *ctx, const struct lys_node *start, const char *nodeid); |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 1044 | |
| 1045 | /** |
Radek Krejci | 0ec51da | 2016-12-14 16:42:03 +0100 | [diff] [blame] | 1046 | * @brief Remove the specified module from its context. |
Radek Krejci | 8c107fe | 2016-10-17 16:00:18 +0200 | [diff] [blame] | 1047 | * |
Radek Krejci | 0ec51da | 2016-12-14 16:42:03 +0100 | [diff] [blame] | 1048 | * Beside the selected module, also all other modules depending on all the modules being removed |
| 1049 | * will be removed as well. |
Radek Krejci | 8c107fe | 2016-10-17 16:00:18 +0200 | [diff] [blame] | 1050 | * |
| 1051 | * libyang internal modules (those present when the context is created) cannot be removed. |
| 1052 | * |
Radek Krejci | 0ec51da | 2016-12-14 16:42:03 +0100 | [diff] [blame] | 1053 | * @param[in] module Module to be removed. |
Radek Krejci | 8c107fe | 2016-10-17 16:00:18 +0200 | [diff] [blame] | 1054 | * @param[in] private_destructor Optional destructor function for private objects assigned |
| 1055 | * to the nodes via lys_set_private(). If NULL, the private objects are not freed by libyang. |
Radek Krejci | 0ec51da | 2016-12-14 16:42:03 +0100 | [diff] [blame] | 1056 | * @return EXIT_SUCCESS or EXIT_FAILURE (in case of invalid parameter). |
Radek Krejci | 8c107fe | 2016-10-17 16:00:18 +0200 | [diff] [blame] | 1057 | */ |
Radek Krejci | 0ec51da | 2016-12-14 16:42:03 +0100 | [diff] [blame] | 1058 | int ly_ctx_remove_module(const struct lys_module *module, |
Radek Krejci | 8c107fe | 2016-10-17 16:00:18 +0200 | [diff] [blame] | 1059 | void (*private_destructor)(const struct lys_node *node, void *priv)); |
| 1060 | |
| 1061 | /** |
| 1062 | * @brief Remove all the modules from the context except the internal modules. Also the addition data in |
| 1063 | * dictionary are kept. |
| 1064 | * |
| 1065 | * @param[in] ctx Context to work in. |
| 1066 | * @param[in] private_destructor Optional destructor function for private objects assigned |
| 1067 | * to the nodes via lys_set_private(). If NULL, the private objects are not freed by libyang. |
| 1068 | */ |
| 1069 | void ly_ctx_clean(struct ly_ctx *ctx, void (*private_destructor)(const struct lys_node *node, void *priv)); |
| 1070 | |
| 1071 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 1072 | * @brief Free all internal structures of the specified context. |
| 1073 | * |
| 1074 | * The function should be used before terminating the application to destroy |
| 1075 | * and free all structures internally used by libyang. If the caller uses |
| 1076 | * multiple contexts, the function should be called for each used context. |
| 1077 | * |
| 1078 | * All instance data are supposed to be freed before destroying the context. |
| 1079 | * Data models are destroyed automatically as part of ly_ctx_destroy() call. |
| 1080 | * |
| 1081 | * @param[in] ctx libyang context to destroy |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 1082 | * @param[in] private_destructor Optional destructor function for private objects assigned |
| 1083 | * to the nodes via lys_set_private(). If NULL, the private objects are not freed by libyang. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1084 | */ |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 1085 | void ly_ctx_destroy(struct ly_ctx *ctx, void (*private_destructor)(const struct lys_node *node, void *priv)); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1086 | |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 1087 | /**@} context */ |
| 1088 | |
| 1089 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 1090 | * @defgroup nodeset Tree nodes set |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 1091 | * @ingroup datatree |
| 1092 | * @ingroup schematree |
| 1093 | * @{ |
| 1094 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 1095 | * Structure and functions to hold and manipulate with sets of nodes from schema or data trees. |
| 1096 | */ |
| 1097 | |
| 1098 | /** |
Radek Krejci | 8f08df1 | 2016-03-21 11:11:30 +0100 | [diff] [blame] | 1099 | * @brief set array of ::ly_set |
| 1100 | * It is kept in union to keep ::ly_set generic for data as well as schema trees |
| 1101 | */ |
| 1102 | union ly_set_set { |
| 1103 | struct lys_node **s; /**< array of pointers to a ::lys_node objects */ |
| 1104 | struct lyd_node **d; /**< array of pointers to a ::lyd_node objects */ |
| 1105 | void **g; /**< dummy array for generic work */ |
| 1106 | }; |
| 1107 | |
| 1108 | /** |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 1109 | * @brief Structure to hold a set of (not necessary somehow connected) ::lyd_node or ::lys_node objects. |
| 1110 | * Caller is supposed to not mix the type of objects added to the set and according to its knowledge about |
| 1111 | * the set content, it is supposed to access the set via the sset, dset or set members of the structure. |
| 1112 | * |
Radek Krejci | 09891a2 | 2016-06-10 10:59:22 +0200 | [diff] [blame] | 1113 | * Until ly_set_rm() or ly_set_rm_index() is used, the set keeps the order of the inserted items as they |
| 1114 | * were added into the set, so the first added item is on array index 0. |
| 1115 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 1116 | * To free the structure, use ly_set_free() function, to manipulate with the structure, use other |
| 1117 | * ly_set_* functions. |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 1118 | */ |
| 1119 | struct ly_set { |
| 1120 | unsigned int size; /**< allocated size of the set array */ |
| 1121 | unsigned int number; /**< number of elements in (used size of) the set array */ |
Radek Krejci | 8f08df1 | 2016-03-21 11:11:30 +0100 | [diff] [blame] | 1122 | union ly_set_set set; /**< set array - union to keep ::ly_set generic for data as well as schema trees */ |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 1123 | }; |
| 1124 | |
| 1125 | /** |
Radek Krejci | 09891a2 | 2016-06-10 10:59:22 +0200 | [diff] [blame] | 1126 | * @brief Option for ly_set_add() to allow duplicities in the ly_set structure so the |
| 1127 | * set is not used as a set, but as a list of (container for) items. |
| 1128 | */ |
| 1129 | #define LY_SET_OPT_USEASLIST 0x01 |
| 1130 | |
| 1131 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 1132 | * @brief Create and initiate new ::ly_set structure. |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 1133 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 1134 | * @return Created ::ly_set structure or NULL in case of error. |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 1135 | */ |
| 1136 | struct ly_set *ly_set_new(void); |
| 1137 | |
| 1138 | /** |
Radek Krejci | e8c1b57 | 2016-07-26 15:09:52 +0200 | [diff] [blame] | 1139 | * @brief Duplicate the existing set. |
| 1140 | * |
| 1141 | * @param[in] set Original set to duplicate |
| 1142 | * @return Duplication of the original set. |
| 1143 | */ |
| 1144 | struct ly_set *ly_set_dup(const struct ly_set *set); |
| 1145 | |
| 1146 | /** |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 1147 | * @brief Add a ::lyd_node or ::lys_node object into the set |
| 1148 | * |
Radek Krejci | 29cb50d | 2016-05-09 16:31:13 +0200 | [diff] [blame] | 1149 | * Since it is a set, the function checks for duplicity and if the |
| 1150 | * node is already in the set, the index of the previously added |
| 1151 | * node is returned. |
| 1152 | * |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 1153 | * @param[in] set Set where the \p node will be added. |
| 1154 | * @param[in] node The ::lyd_node or ::lys_node object to be added into the \p set; |
Radek Krejci | 09891a2 | 2016-06-10 10:59:22 +0200 | [diff] [blame] | 1155 | * @param[in] options Options to change behavior of the function. Accepted options are: |
| 1156 | * - #LY_SET_OPT_USEASLIST - do not check for duplicities |
Radek Krejci | 29cb50d | 2016-05-09 16:31:13 +0200 | [diff] [blame] | 1157 | * @return -1 on failure, index of the \p node in the set on success |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 1158 | */ |
Radek Krejci | 09891a2 | 2016-06-10 10:59:22 +0200 | [diff] [blame] | 1159 | int ly_set_add(struct ly_set *set, void *node, int options); |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 1160 | |
| 1161 | /** |
Radek Krejci | 99e6d9a | 2016-10-20 13:01:43 +0200 | [diff] [blame] | 1162 | * @brief Get know if the set contains the specified object. |
| 1163 | * @param[in] set Set to explore. |
| 1164 | * @param[in] node Object to be found in the set. |
| 1165 | * @return Index of the object in the set or -1 if the object is not present in the set. |
Radek Krejci | 3e11229 | 2016-10-20 13:10:30 +0200 | [diff] [blame] | 1166 | */ |
Radek Krejci | 99e6d9a | 2016-10-20 13:01:43 +0200 | [diff] [blame] | 1167 | int ly_set_contains(const struct ly_set *set, void *node); |
| 1168 | |
| 1169 | /** |
Radek Krejci | 29ed408 | 2016-05-09 14:25:56 +0200 | [diff] [blame] | 1170 | * @brief Remove all objects from the set, but keep the set container for further use. |
| 1171 | * |
| 1172 | * @param[in] set Set to clean. |
| 1173 | * @return 0 on success |
| 1174 | */ |
| 1175 | int ly_set_clean(struct ly_set *set); |
| 1176 | |
| 1177 | /** |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 1178 | * @brief Remove a ::lyd_node or ::lys_node object from the set. |
| 1179 | * |
| 1180 | * Note that after removing a node from a set, indexes of other nodes in the set can change |
| 1181 | * (the last object is placed instead of the removed object). |
| 1182 | * |
| 1183 | * @param[in] set Set from which the \p node will be removed. |
| 1184 | * @param[in] node The ::lyd_node or ::lys_node object to be removed from the \p set; |
| 1185 | * @return 0 on success |
| 1186 | */ |
| 1187 | int ly_set_rm(struct ly_set *set, void *node); |
| 1188 | |
| 1189 | /** |
| 1190 | * @brief Remove a ::lyd_node or ::lys_node object from the set index. |
| 1191 | * |
| 1192 | * Note that after removing a node from a set, indexes of other nodes in the set can change |
| 1193 | * (the last object is placed instead of the removed object). |
| 1194 | * |
| 1195 | * @param[in] set Set from which a node will be removed. |
| 1196 | * @param[in] index Index of the ::lyd_node or ::lys_node object in the \p set to be removed from the \p set; |
| 1197 | * @return 0 on success |
| 1198 | */ |
| 1199 | int ly_set_rm_index(struct ly_set *set, unsigned int index); |
| 1200 | |
| 1201 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 1202 | * @brief Free the ::ly_set data. Frees only the set structure content, not the referred data. |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 1203 | * |
| 1204 | * @param[in] set The set to be freed. |
| 1205 | */ |
| 1206 | void ly_set_free(struct ly_set *set); |
| 1207 | |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 1208 | /**@} nodeset */ |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 1209 | |
| 1210 | /** |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame] | 1211 | * @defgroup printerflags Printer flags |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 1212 | * @ingroup datatree |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame] | 1213 | * |
| 1214 | * Validity flags for data nodes. |
| 1215 | * |
| 1216 | * @{ |
| 1217 | */ |
Michal Vasko | 6216f27 | 2016-10-18 11:49:47 +0200 | [diff] [blame] | 1218 | #define LYP_WITHSIBLINGS 0x01 /**< Flag for printing also the (following) sibling nodes of the data node. */ |
| 1219 | #define LYP_FORMAT 0x02 /**< Flag for formatted output. */ |
| 1220 | #define LYP_KEEPEMPTYCONT 0x04 /**< Preserve empty non-presence containers */ |
| 1221 | #define LYP_WD_MASK 0xF0 /**< Mask for with-defaults modes */ |
| 1222 | #define LYP_WD_EXPLICIT 0x00 /**< Explicit mode - print only data explicitly being present in the data tree. |
| 1223 | Note that this is the default value when no WD option is specified. */ |
| 1224 | #define LYP_WD_TRIM 0x10 /**< Do not print the nodes with the value equal to their default value */ |
| 1225 | #define LYP_WD_ALL 0x20 /**< Include implicit default nodes */ |
| 1226 | #define LYP_WD_ALL_TAG 0x40 /**< Same as #LYP_WD_ALL but also adds attribute 'default' with value 'true' to |
| 1227 | all nodes that has its default value. The 'default' attribute has namespace: |
| 1228 | urn:ietf:params:xml:ns:netconf:default:1.0 and thus the attributes are |
| 1229 | printed only when the ietf-netconf-with-defaults module is present in libyang |
| 1230 | context. */ |
| 1231 | #define LYP_WD_IMPL_TAG 0x80 /**< Same as LYP_WD_ALL_TAG but the attributes are added only to the nodes that |
| 1232 | are not explicitly present in the original data tree despite their |
| 1233 | value is equal to their default value. There is the same limitation regarding |
| 1234 | the presence of ietf-netconf-with-defaults module in libyang context. */ |
Michal Vasko | afa7a64 | 2016-10-18 15:11:38 +0200 | [diff] [blame] | 1235 | #define LYP_NETCONF 0x100 /**< Print the data tree for use in NETCONF meaning: |
Michal Vasko | 6216f27 | 2016-10-18 11:49:47 +0200 | [diff] [blame] | 1236 | - for RPC output - skip the top-level RPC node, |
| 1237 | - for action output - skip all the parents of and the action node itself, |
| 1238 | - for action input - enclose the data in an action element in the base YANG namespace, |
| 1239 | - for all other data - print the whole data tree normally. */ |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame] | 1240 | |
| 1241 | /** |
| 1242 | * @} |
| 1243 | */ |
| 1244 | |
| 1245 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 1246 | * @defgroup logger Logger |
| 1247 | * @{ |
| 1248 | * |
| 1249 | * Publicly visible functions and values of the libyang logger. For more |
| 1250 | * information, see \ref howtologger. |
| 1251 | */ |
| 1252 | |
| 1253 | /** |
| 1254 | * @typedef LY_LOG_LEVEL |
| 1255 | * @brief Verbosity levels of the libyang logger. |
| 1256 | */ |
| 1257 | typedef enum { |
Michal Vasko | 8f7e8d9 | 2016-07-01 11:33:58 +0200 | [diff] [blame] | 1258 | LY_LLSILENT = -1, /**< Print no messages. */ |
| 1259 | LY_LLERR = 0, /**< Print only error messages, default value. */ |
| 1260 | LY_LLWRN, /**< Print error and warning messages. */ |
| 1261 | LY_LLVRB, /**< Besides errors and warnings, print some other verbose messages. */ |
| 1262 | LY_LLDBG /**< Print all messages including some development debug messages. */ |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 1263 | } LY_LOG_LEVEL; |
| 1264 | |
| 1265 | /** |
| 1266 | * @brief Set logger verbosity level. |
| 1267 | * @param[in] level Verbosity level. |
| 1268 | */ |
| 1269 | void ly_verb(LY_LOG_LEVEL level); |
| 1270 | |
| 1271 | /** |
Michal Vasko | f1d62cf | 2015-12-07 13:17:11 +0100 | [diff] [blame] | 1272 | * @brief Set logger callback. |
Michal Vasko | 1366114 | 2016-04-11 10:53:53 +0200 | [diff] [blame] | 1273 | * |
| 1274 | * !IMPORTANT! If an error has a specific error-app-tag defined in the model, it will NOT be set |
| 1275 | * at the time of calling this callback. It will be set right after, so to retrieve it |
| 1276 | * it must be checked afterwards with ly_errapptag(). |
| 1277 | * |
Michal Vasko | f1d62cf | 2015-12-07 13:17:11 +0100 | [diff] [blame] | 1278 | * @param[in] clb Logging callback. |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 1279 | * @param[in] path flag to resolve and provide path as the third parameter of the callback function. In case of |
| 1280 | * validation and some other errors, it can be useful to get the path to the problematic element. Note, |
| 1281 | * that according to the tree type and the specific situation, the path can slightly differs (keys |
| 1282 | * presence) or it can be NULL, so consider it as an optional parameter. If the flag is 0, libyang will |
| 1283 | * not bother with resolving the path. |
Michal Vasko | f1d62cf | 2015-12-07 13:17:11 +0100 | [diff] [blame] | 1284 | */ |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 1285 | void ly_set_log_clb(void (*clb)(LY_LOG_LEVEL level, const char *msg, const char *path), int path); |
Michal Vasko | f1d62cf | 2015-12-07 13:17:11 +0100 | [diff] [blame] | 1286 | |
| 1287 | /** |
| 1288 | * @brief Get logger callback. |
| 1289 | * @return Logger callback (can be NULL). |
| 1290 | */ |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 1291 | void (*ly_get_log_clb(void))(LY_LOG_LEVEL, const char *, const char *); |
Michal Vasko | f1d62cf | 2015-12-07 13:17:11 +0100 | [diff] [blame] | 1292 | |
| 1293 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 1294 | * @typedef LY_ERR |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 1295 | * @brief libyang's error codes available via ly_errno extern variable. |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 1296 | * @ingroup logger |
| 1297 | */ |
| 1298 | typedef enum { |
Radek Krejci | ae6817a | 2015-08-10 14:02:06 +0200 | [diff] [blame] | 1299 | LY_SUCCESS, /**< no error, not set by functions, included just to complete #LY_ERR enumeration */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1300 | LY_EMEM, /**< Memory allocation failure */ |
| 1301 | LY_ESYS, /**< System call failure */ |
| 1302 | LY_EINVAL, /**< Invalid value */ |
| 1303 | LY_EINT, /**< Internal error */ |
| 1304 | LY_EVALID /**< Validation failure */ |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 1305 | } LY_ERR; |
Radek Krejci | 7d9f46a | 2016-01-29 13:53:18 +0100 | [diff] [blame] | 1306 | |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 1307 | /** |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1308 | * @typedef LY_VECODE |
| 1309 | * @brief libyang's codes of validation error. Whenever ly_errno is set to LY_EVALID, the ly_vecode is also set |
| 1310 | * to the appropriate LY_VECODE value. |
Radek Krejci | a37b39c | 2016-03-09 16:38:18 +0100 | [diff] [blame] | 1311 | * @ingroup logger |
| 1312 | */ |
| 1313 | typedef enum { |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1314 | LYVE_SUCCESS = 0, /**< no error */ |
Radek Krejci | a37b39c | 2016-03-09 16:38:18 +0100 | [diff] [blame] | 1315 | |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1316 | LYVE_XML_MISS, /**< missing XML object */ |
| 1317 | LYVE_XML_INVAL, /**< invalid XML object */ |
| 1318 | LYVE_XML_INCHAR, /**< invalid XML character */ |
Radek Krejci | a37b39c | 2016-03-09 16:38:18 +0100 | [diff] [blame] | 1319 | |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1320 | LYVE_EOF, /**< unexpected end of input data */ |
| 1321 | LYVE_INSTMT, /**< invalid statement (schema) */ |
| 1322 | /* */ |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 1323 | LYVE_INPAR, /**< invalid (in)direct parent (schema) */ |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1324 | LYVE_INID, /**< invalid identifier (schema) */ |
| 1325 | LYVE_INDATE, /**< invalid date format */ |
| 1326 | LYVE_INARG, /**< invalid value of a statement argument (schema) */ |
| 1327 | LYVE_MISSSTMT, /**< missing required statement (schema) */ |
| 1328 | /* */ |
| 1329 | LYVE_MISSARG, /**< missing required statement argument (schema) */ |
| 1330 | LYVE_TOOMANY, /**< too many instances of some object */ |
| 1331 | LYVE_DUPID, /**< duplicated identifier (schema) */ |
| 1332 | LYVE_DUPLEAFLIST, /**< multiple instances of leaf-list */ |
| 1333 | LYVE_DUPLIST, /**< multiple instances of list */ |
Michal Vasko | a540df2 | 2016-04-11 16:14:35 +0200 | [diff] [blame] | 1334 | LYVE_NOUNIQ, /**< unique leaves match on 2 list instances (data) */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1335 | LYVE_ENUM_INVAL, /**< invalid enum value (schema) */ |
| 1336 | LYVE_ENUM_INNAME, /**< invalid enum name (schema) */ |
| 1337 | /* */ |
| 1338 | /* */ |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1339 | LYVE_ENUM_WS, /**< enum name with leading/trailing whitespaces (schema) */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1340 | LYVE_BITS_INVAL, /**< invalid bits value (schema) */ |
| 1341 | LYVE_BITS_INNAME, /**< invalid bits name (schema) */ |
| 1342 | /* */ |
| 1343 | /* */ |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1344 | LYVE_INMOD, /**< invalid module name */ |
| 1345 | /* */ |
| 1346 | LYVE_KEY_NLEAF, /**< list key is not a leaf (schema) */ |
| 1347 | LYVE_KEY_TYPE, /**< invalid list key type (schema) */ |
| 1348 | LYVE_KEY_CONFIG, /**< key config value differs from the list config value */ |
| 1349 | LYVE_KEY_MISS, /**< list key not found (schema) */ |
| 1350 | LYVE_KEY_DUP, /**< duplicated key identifier (schema) */ |
| 1351 | LYVE_INREGEX, /**< invalid regular expression (schema) */ |
| 1352 | LYVE_INRESOLV, /**< no resolvents found (schema) */ |
| 1353 | LYVE_INSTATUS, /**< invalid derivation because of status (schema) */ |
Radek Krejci | d8fb03c | 2016-06-13 15:52:22 +0200 | [diff] [blame] | 1354 | LYVE_CIRC_LEAFREFS,/**< circular chain of leafrefs detected (schema) */ |
Radek Krejci | e8c1b57 | 2016-07-26 15:09:52 +0200 | [diff] [blame] | 1355 | LYVE_CIRC_FEATURES,/**< circular chain of features detected (schema) */ |
Radek Krejci | 151b8cc | 2016-06-22 10:14:21 +0200 | [diff] [blame] | 1356 | LYVE_CIRC_IMPORTS, /**< circular chain of imports detected (schema) */ |
| 1357 | LYVE_CIRC_INCLUDES,/**< circular chain of includes detected (schema) */ |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 1358 | LYVE_INVER, /**< non-matching YANG versions of module and its submodules (schema) */ |
Radek Krejci | 0fd6a99 | 2016-11-08 19:42:20 +0100 | [diff] [blame] | 1359 | LYVE_SUBMODULE, /**< submodule given instead of a module */ |
Radek Krejci | a37b39c | 2016-03-09 16:38:18 +0100 | [diff] [blame] | 1360 | |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1361 | LYVE_OBSDATA, /**< obsolete data instantiation (data) */ |
| 1362 | /* */ |
| 1363 | LYVE_NORESOLV, /**< no resolvents found for an expression (data) */ |
| 1364 | LYVE_INELEM, /**< invalid element (data) */ |
| 1365 | /* */ |
| 1366 | LYVE_MISSELEM, /**< missing required element (data) */ |
| 1367 | LYVE_INVAL, /**< invalid value of an element (data) */ |
Radek Krejci | 9bfcbde | 2016-04-07 16:30:15 +0200 | [diff] [blame] | 1368 | LYVE_INVALATTR, /**< invalid attribute value (data) */ |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1369 | LYVE_INATTR, /**< invalid attribute in an element (data) */ |
| 1370 | LYVE_MISSATTR, /**< missing attribute in an element (data) */ |
Michal Vasko | 6ac6828 | 2016-04-11 10:56:47 +0200 | [diff] [blame] | 1371 | LYVE_NOCONSTR, /**< value out of range/length/pattern (data) */ |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1372 | LYVE_INCHAR, /**< unexpected characters (data) */ |
| 1373 | LYVE_INPRED, /**< predicate resolution fail (data) */ |
| 1374 | LYVE_MCASEDATA, /**< data for more cases of a choice (data) */ |
Michal Vasko | 6ac6828 | 2016-04-11 10:56:47 +0200 | [diff] [blame] | 1375 | LYVE_NOMUST, /**< unsatisfied must condition (data) */ |
| 1376 | LYVE_NOWHEN, /**< unsatisfied when condition (data) */ |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1377 | LYVE_INORDER, /**< invalid order of elements (data) */ |
Radek Krejci | 03b71f7 | 2016-03-16 11:10:09 +0100 | [diff] [blame] | 1378 | LYVE_INWHEN, /**< irresolvable when condition (data) */ |
Michal Vasko | 6ac6828 | 2016-04-11 10:56:47 +0200 | [diff] [blame] | 1379 | LYVE_NOMIN, /**< min-elements constraint not honored (data) */ |
| 1380 | LYVE_NOMAX, /**< max-elements constraint not honored (data) */ |
| 1381 | LYVE_NOREQINS, /**< required instance does not exits (data) */ |
| 1382 | LYVE_NOLEAFREF, /**< leaf pointed to by leafref does not exist (data) */ |
| 1383 | LYVE_NOMANDCHOICE, /**< no mandatory choice case branch exists (data) */ |
Radek Krejci | a37b39c | 2016-03-09 16:38:18 +0100 | [diff] [blame] | 1384 | |
Michal Vasko | 5b3492c | 2016-07-20 09:37:40 +0200 | [diff] [blame] | 1385 | LYVE_XPATH_INSNODE,/**< schema node not found */ |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1386 | LYVE_XPATH_INTOK, /**< unexpected XPath token */ |
| 1387 | LYVE_XPATH_EOF, /**< unexpected end of an XPath expression */ |
| 1388 | LYVE_XPATH_INOP, /**< invalid XPath operation operands */ |
| 1389 | /* */ |
| 1390 | LYVE_XPATH_INCTX, /**< invalid XPath context type */ |
Michal Vasko | 541dff4 | 2016-10-26 11:29:25 +0200 | [diff] [blame] | 1391 | LYVE_XPATH_INMOD, /**< invalid module name */ |
Michal Vasko | 9390977 | 2016-10-26 10:32:10 +0200 | [diff] [blame] | 1392 | LYVE_XPATH_INFUNC, /**< invalid XPath function name */ |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1393 | LYVE_XPATH_INARGCOUNT, /**< invalid number of arguments for an XPath function */ |
Michal Vasko | 6fae136 | 2016-03-11 15:10:00 +0100 | [diff] [blame] | 1394 | LYVE_XPATH_INARGTYPE, /**< invalid type of arguments for an XPath function */ |
Michal Vasko | 11f8da7 | 2016-08-24 15:54:57 +0200 | [diff] [blame] | 1395 | LYVE_XPATH_DUMMY, /**< invaid use of the XPath dummy node */ |
Michal Vasko | 6fae136 | 2016-03-11 15:10:00 +0100 | [diff] [blame] | 1396 | |
| 1397 | LYVE_PATH_INCHAR, /**< invalid characters (path) */ |
Michal Vasko | e733d68 | 2016-03-14 09:08:27 +0100 | [diff] [blame] | 1398 | LYVE_PATH_INMOD, /**< invalid module name (path) */ |
| 1399 | LYVE_PATH_MISSMOD, /**< missing module name (path) */ |
Michal Vasko | 6fae136 | 2016-03-11 15:10:00 +0100 | [diff] [blame] | 1400 | LYVE_PATH_INNODE, /**< invalid node name (path) */ |
Michal Vasko | 6fae136 | 2016-03-11 15:10:00 +0100 | [diff] [blame] | 1401 | LYVE_PATH_INKEY, /**< invalid key name (path) */ |
| 1402 | LYVE_PATH_MISSKEY, /**< missing some list keys (path) */ |
| 1403 | LYVE_PATH_EXISTS, /**< target node already exists (path) */ |
| 1404 | LYVE_PATH_MISSPAR, /**< some parent of the target node is missing (path) */ |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1405 | } LY_VECODE; |
Radek Krejci | a37b39c | 2016-03-09 16:38:18 +0100 | [diff] [blame] | 1406 | |
| 1407 | /** |
Radek Krejci | 7d9f46a | 2016-01-29 13:53:18 +0100 | [diff] [blame] | 1408 | * @cond INTERNAL |
Radek Krejci | 386714d | 2016-02-15 10:24:30 +0100 | [diff] [blame] | 1409 | * Get address of (thread-specific) `ly_errno' variable. |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 1410 | */ |
Radek Krejci | 7d9f46a | 2016-01-29 13:53:18 +0100 | [diff] [blame] | 1411 | LY_ERR *ly_errno_location(void); |
| 1412 | |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1413 | LY_VECODE *ly_vecode_location(void); |
Radek Krejci | a37b39c | 2016-03-09 16:38:18 +0100 | [diff] [blame] | 1414 | |
Radek Krejci | 7d9f46a | 2016-01-29 13:53:18 +0100 | [diff] [blame] | 1415 | /** |
| 1416 | * @endcond INTERNAL |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 1417 | * @brief libyang specific (thread-safe) errno (see #LY_ERR for the list of possible values and their meaning). |
Radek Krejci | 7d9f46a | 2016-01-29 13:53:18 +0100 | [diff] [blame] | 1418 | */ |
| 1419 | #define ly_errno (*ly_errno_location()) |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 1420 | |
Radek Krejci | 386714d | 2016-02-15 10:24:30 +0100 | [diff] [blame] | 1421 | /** |
Radek Krejci | a37b39c | 2016-03-09 16:38:18 +0100 | [diff] [blame] | 1422 | * @brief libyang's validation error code |
| 1423 | */ |
Michal Vasko | f5035ce | 2016-03-11 10:21:31 +0100 | [diff] [blame] | 1424 | #define ly_vecode (*ly_vecode_location()) |
Radek Krejci | a37b39c | 2016-03-09 16:38:18 +0100 | [diff] [blame] | 1425 | |
| 1426 | /** |
Michal Vasko | 1366114 | 2016-04-11 10:53:53 +0200 | [diff] [blame] | 1427 | * @brief Get the last (thread-specific) error message. If the coresponding module defined |
| 1428 | * a specific error message, it will be used instead the default one. |
Radek Krejci | 6e8fc0b | 2016-02-16 14:33:37 +0100 | [diff] [blame] | 1429 | * |
| 1430 | * Sometimes, the error message is extended with path of the element where is the problem. |
| 1431 | * The path is available via ly_errpath(). |
| 1432 | * |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 1433 | * @return Text of the last error message, empty string if there is no error. |
Radek Krejci | 386714d | 2016-02-15 10:24:30 +0100 | [diff] [blame] | 1434 | */ |
| 1435 | const char *ly_errmsg(void); |
| 1436 | |
Radek Krejci | 6e8fc0b | 2016-02-16 14:33:37 +0100 | [diff] [blame] | 1437 | /** |
| 1438 | * @brief Get the last (thread-specific) path of the element where was an error. |
| 1439 | * |
| 1440 | * The path always corresponds to the error message available via ly_errmsg(), so |
| 1441 | * whenever a subsequent error message is printed, the path is erased or rewritten. |
Radek Krejci | 3cc1096 | 2016-04-13 15:03:27 +0200 | [diff] [blame] | 1442 | * The path reflects the type of the processed tree - data path for data tree functions |
| 1443 | * and schema path in case of schema tree functions. In case of processing YIN schema |
| 1444 | * or XML data, the path can be just XML path. In such a case, the corresponding |
| 1445 | * ly_vecode (value 1-3) is set. |
Radek Krejci | 6e8fc0b | 2016-02-16 14:33:37 +0100 | [diff] [blame] | 1446 | * |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 1447 | * @return Path of the error element, empty string if error path does not apply to the last error. |
Radek Krejci | 6e8fc0b | 2016-02-16 14:33:37 +0100 | [diff] [blame] | 1448 | */ |
| 1449 | const char *ly_errpath(void); |
| 1450 | |
Michal Vasko | 1366114 | 2016-04-11 10:53:53 +0200 | [diff] [blame] | 1451 | /** |
| 1452 | * @brief Get the last (thread-specific) error-app-tag if there was a specific one defined |
| 1453 | * in the module for the last error. |
| 1454 | * |
| 1455 | * The app-tag always corresponds to the error message available via ly_errmsg(), so |
| 1456 | * whenever a subsequent error message is printed, the app-tag is erased or rewritten. |
| 1457 | * |
Radek Krejci | b50551c | 2016-04-19 09:15:38 +0200 | [diff] [blame] | 1458 | * @return Error-app-tag of the last error, empty string if the error-app-tag does not apply to the last error. |
Michal Vasko | 1366114 | 2016-04-11 10:53:53 +0200 | [diff] [blame] | 1459 | */ |
| 1460 | const char *ly_errapptag(void); |
| 1461 | |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 1462 | /**@} logger */ |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 1463 | |
Radek Krejci | 39d8d0d | 2015-08-17 13:42:45 +0200 | [diff] [blame] | 1464 | #ifdef __cplusplus |
| 1465 | } |
| 1466 | #endif |
| 1467 | |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 1468 | #endif /* LY_LIBYANG_H_ */ |