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 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in |
| 15 | * the documentation and/or other materials provided with the |
| 16 | * distribution. |
| 17 | * 3. Neither the name of the Company nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this |
| 19 | * software without specific prior written permission. |
| 20 | */ |
| 21 | |
| 22 | #ifndef LY_LIBYANG_H_ |
| 23 | #define LY_LIBYANG_H_ |
| 24 | |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 27 | #include "tree_schema.h" |
| 28 | #include "tree_data.h" |
Radek Krejci | c6704c8 | 2015-10-06 11:12:45 +0200 | [diff] [blame] | 29 | #include "xml.h" |
Radek Krejci | 41912fe | 2015-10-22 10:22:12 +0200 | [diff] [blame] | 30 | #include "dict.h" |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 31 | |
Radek Krejci | 39d8d0d | 2015-08-17 13:42:45 +0200 | [diff] [blame] | 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 36 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 37 | * @mainpage About |
| 38 | * |
| 39 | * libyang is a library implementing processing of the YANG schemas and data modeled by the YANG language. The |
| 40 | * library is implemented in C for GNU/Linux and provides C API. |
| 41 | * |
| 42 | * @section about-features Main Features |
| 43 | * |
| 44 | * - Parsing (and validating) schemas in YIN format. |
| 45 | * - Parsing, validating and printing instance data in XML format. |
| 46 | * - Parsing, validating and printing instance data in JSON format. |
| 47 | * - Manipulation with the instance data. |
| 48 | * |
| 49 | * - \todo Parsing (and validating) schemas in YANG format. |
| 50 | * |
| 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 |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 82 | * - @subpage howtoxml |
| 83 | * - @subpage howtothreads |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 84 | * - @subpage howtologger |
| 85 | */ |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 86 | |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 87 | /** @page howtocontext Context |
| 88 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 89 | * 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] | 90 | * |
| 91 | * The first step in libyang is to create a new context using ly_ctx_new(). It returns a handler |
| 92 | * used in the following work. |
| 93 | * |
| 94 | * When creating a new context, search dir can be specified (NULL is accepted) to provide directory |
| 95 | * where libyang will automatically search for schemas being imported or included. The search path |
| 96 | * can be later changed via ly_ctx_set_searchdir() function. Before exploring the specified search |
| 97 | * dir, libyang tries to get imported and included schemas from the current working directory first. |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 98 | * This automatic searching can be completely avoided when the caller sets module searching callback |
| 99 | * (#ly_module_clb) via ly_ctx_set_module_clb(). |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 100 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 101 | * Schemas are added into the context using [parser functions](@ref howtoschemasparsers) - \b lys_parse_*() or \b lyd_parse_*(). |
| 102 | * In case of schemas, also ly_ctx_load_module() can be used - in that case the #ly_module_clb or automatic |
| 103 | * search in working directory and in the searchpath is used. Note, that functions for schemas have \b lys_ |
| 104 | * prefix while functions for instance data have \b lyd_ prefix. |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 105 | * |
Radek Krejci | f647e61 | 2015-07-30 11:36:07 +0200 | [diff] [blame] | 106 | * Context can hold multiple revisons of the same schema. |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 107 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 108 | * Context holds all modules and their submodules internally. The list of available module names is |
| 109 | * provided via ly_ctx_get_module_names() functions. Similarly, caller can get also a list of submodules |
| 110 | * names of a specific module using ly_ctx_get_submodule_names() function. The returned names can be |
| 111 | * subsequently used to get the (sub)module structures using ly_ctx_get_module() and ly_ctx_get_submodule(). |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 112 | * Alternatively, the ly_ctx_info() function can be used to get complex information about the schemas in the context |
| 113 | * in the form of data tree defined by |
| 114 | * <a href="https://tools.ietf.org/html/draft-ietf-netconf-yang-library-01">ietf-yang-library</a> schema. |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 115 | * |
| 116 | * Modules held by a context cannot be removed one after one. The only way how to \em change modules in the |
| 117 | * context is to create a new context and remove the old one. To remove a context, there is ly_ctx_destroy() |
| 118 | * function. |
| 119 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 120 | * - @subpage howtocontextdict |
| 121 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 122 | * \note API for this group of functions is available in the [context module](@ref context). |
| 123 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 124 | * Functions List |
| 125 | * -------------- |
| 126 | * - ly_ctx_new() |
| 127 | * - ly_ctx_set_searchdir() |
| 128 | * - ly_ctx_get_searchdir() |
| 129 | * - ly_ctx_set_module_clb() |
| 130 | * - ly_ctx_get_module_clb() |
| 131 | * - ly_ctx_load_module() |
| 132 | * - ly_ctx_info() |
| 133 | * - ly_ctx_get_module_names() |
| 134 | * - ly_ctx_get_module() |
| 135 | * - ly_ctx_get_module_by_ns() |
| 136 | * - ly_ctx_get_submodule_names() |
| 137 | * - ly_ctx_get_submodule() |
| 138 | * - ly_ctx_destroy() |
| 139 | */ |
| 140 | |
| 141 | /** |
| 142 | * @page howtocontextdict Context Dictionary |
| 143 | * |
| 144 | * Context includes dictionary to store strings more effectively. The most of strings repeats quite often in schema |
| 145 | * as well as data trees. Therefore, instead of allocating those strings each time they appear, libyang stores them |
| 146 | * as records in the dictionary. The basic API to the context dictionary is public, so even a caller application can |
| 147 | * use the dictionary. |
| 148 | * |
| 149 | * To insert a string into the dictionary, caller can use lydict_insert() (adding a constant string) or |
| 150 | * lydict_insert_zc() (for dynamically allocated strings that won't be used by the caller after its insertion into |
| 151 | * the dictionary). Both functions return the pointer to the inserted string in the dictionary record. |
| 152 | * |
| 153 | * To remove (reference of the) string from the context dictionary, lydict_remove() is supposed to be used. |
| 154 | * |
| 155 | * \note Incorrect usage of the dictionary can break libyang functionality. |
| 156 | * |
| 157 | * \note API for this group of functions is described in the [XML Parser module](@ref dict). |
| 158 | * |
| 159 | * Functions List |
| 160 | * -------------- |
| 161 | * - lydict_insert() |
| 162 | * - lydict_insert_zc() |
| 163 | * - lydict_remove() |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 164 | */ |
| 165 | |
| 166 | /** |
| 167 | * @page howtoschemas Schemas |
| 168 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 169 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 170 | * 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^] | 171 | * its [context](@ref howtocontext) and loaded using [parser functions](@ref howtoschemasparsers). It means, that |
| 172 | * 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] | 173 | * access data model definitions. |
| 174 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 175 | * Schema tree nodes are able to hold private objects (via a pointer to a structure, function, variable, ...) used by |
| 176 | * a caller application. Such an object can be assigned to a specific node using lys_set_private() function. |
| 177 | * Note that the object is not freed by libyang when the context is being destroyed. So the caller is responsible |
| 178 | * for freeing the provided structure after the context is destroyed or the private pointer is set to NULL in |
| 179 | * appropriate schema nodes where the object was previously set. On the other hand, freeing the object while the schema |
| 180 | * tree is still used can lead to a segmentation fault. |
| 181 | * |
| 182 | * - @subpage howtoschemasparsers |
| 183 | * - @subpage howtoschemasfeatures |
| 184 | * - @subpage howtoschemasprinters |
| 185 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 186 | * \note There are many functions to access information from the schema trees. Details are available in |
| 187 | * the [Schema Tree module](@ref schematree). |
| 188 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 189 | * Functions List (not assigned to above subsections) |
| 190 | * -------------------------------------------------- |
| 191 | * - lys_get_node() |
| 192 | * - lys_get_next() |
| 193 | * - lys_parent() |
| 194 | * - lys_set_private() |
| 195 | */ |
| 196 | |
| 197 | /** |
| 198 | * @page howtoschemasparsers Parsing Schemas |
| 199 | * |
| 200 | * Schema parser allows to read schema from a specific format. libyang supports the following schema formats: |
| 201 | * |
| 202 | * - YANG |
| 203 | * |
| 204 | * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020). |
| 205 | * Currently, only YANG 1.0 is supported. |
| 206 | * |
| 207 | * \todo YANG input is not yet implemented |
| 208 | * |
| 209 | * - YIN |
| 210 | * |
| 211 | * Alternative XML-based format to YANG. The details can be found in |
| 212 | * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11). |
| 213 | * |
| 214 | * When the [context](@ref howtocontext) is created, it already contains the following three schemas, which |
| 215 | * are implemented internally by libyang: * |
| 216 | * - ietf-inet-types@2013-07-15 |
| 217 | * - ietf-yang-types@2013-07-15 |
| 218 | * - ietf-yang-library@2015-07-03 |
| 219 | * |
| 220 | * Other schemas can be added to the context manually as described in [context page](@ref howtocontext) by the functions |
| 221 | * listed below. Besides the schema parser functions, it is also possible to use ly_ctx_load_module() which tries to |
| 222 | * find the required schema automatically - using #ly_module_clb or automatic search in working directory and in the |
| 223 | * context's searchpath. |
| 224 | * |
| 225 | * Functions List |
| 226 | * -------------- |
| 227 | * - lys_parse_data() |
| 228 | * - lys_parse_fd() |
| 229 | * - lys_parse_path() |
| 230 | * - ly_ctx_set_module_clb() |
| 231 | * - ly_ctx_load_module() |
| 232 | */ |
| 233 | |
| 234 | /** |
| 235 | * @page howtoschemasfeatures YANG Features Manipulation |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 236 | * |
| 237 | * The group of functions prefixed by \b lys_features_ are used to access and manipulate with the schema's |
| 238 | * features. |
| 239 | * |
| 240 | * The first two functions are used to access information about the features in the schema. |
| 241 | * lys_features_list() provides list of all features defined in the specific schema and its |
| 242 | * submodules. Optionally, it can also provides information about the state of all features. |
| 243 | * Alternatively, caller can use lys_features_state() function to get state of one specific |
| 244 | * feature. |
| 245 | * |
| 246 | * The remaining two functions, lys_features_enable() and lys_features_disable(), are used |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 247 | * to enable and disable the specific feature (or all via \b "*"). By default, when the module |
| 248 | * is loaded by libyang parser, all features are disabled. |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 249 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 250 | * 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] | 251 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 252 | * Note, that the feature's state can affect some of the output formats (e.g. Tree format). |
| 253 | * |
| 254 | * Functions List |
| 255 | * -------------- |
| 256 | * - lys_features_list() |
| 257 | * - lys_features_enable() |
| 258 | * - lys_features_disable() |
| 259 | * - lys_features_state() |
| 260 | * - lys_is_disabled() |
| 261 | */ |
| 262 | |
| 263 | /** |
| 264 | * @page howtoschemasprinters Printing Schemas |
| 265 | * |
| 266 | * Schema printers allows to serialize internal representation of a schema module in a specific format. libyang |
| 267 | * supports the following schema formats for printing: |
| 268 | * |
| 269 | * - YANG |
| 270 | * |
| 271 | * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020). |
| 272 | * Currently, only YANG 1.0 is supported. |
| 273 | * |
| 274 | * - YIN |
| 275 | * |
| 276 | * Alternative XML-based format to YANG. The details can be found in |
| 277 | * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11). |
| 278 | * |
| 279 | * \todo YIN output is not yet implemented |
| 280 | * |
| 281 | * - Tree |
| 282 | * |
| 283 | * Simple tree structure of the module. |
| 284 | * |
| 285 | * - Info |
| 286 | * |
| 287 | * Detailed information about the specific node in the schema tree. |
| 288 | * It allows to print information not only about a specific module, but also about its specific part: |
| 289 | * |
| 290 | * - absolute-schema-nodeid |
| 291 | * |
| 292 | * e.g. \a `/modules/module-set-id` in \a `ietf-yang-library` module |
| 293 | * |
| 294 | * - <b>typedef/</b>typedef-name |
| 295 | * |
| 296 | * e.g. \a `typedef/revision-identifier` in \a `ietf-yang-library` module |
| 297 | * |
| 298 | * - <b>feature/</b>feature-name |
| 299 | * |
| 300 | * e.g. \a `feature/ssh` in \a `ietf-netconf-server` module |
| 301 | * |
| 302 | * - <b>grouping/</b>grouping-name/descendant-schema-nodeid |
| 303 | * |
| 304 | * e.g. \a `grouping/module` or \a `grouping/module/module/submodules` in \a `ietf-yang-library` module |
| 305 | * |
| 306 | * - <b>type/</b>leaf-or-leaflist |
| 307 | * |
| 308 | * e.g. \a `type/modules/module-set-id` in \a `ietf-yang-library` module |
| 309 | * |
| 310 | * Printer functions allow to print to the different outputs including a callback function which allows caller |
| 311 | * to have a full control of the output data - libyang passes to the callback a private argument (some internal |
| 312 | * data provided by a caller of lys_print_clb()), string buffer and number of characters to print. Note that the |
| 313 | * callback is supposed to be called multiple times during the lys_print_clb() execution. |
| 314 | * |
| 315 | * Functions List |
| 316 | * -------------- |
| 317 | * - lys_print_mem() |
| 318 | * - lys_print_fd() |
| 319 | * - lys_print_file() |
| 320 | * - lys_print_clb() |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 321 | */ |
| 322 | |
| 323 | /** |
| 324 | * @page howtodata Data Instances |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 325 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 326 | * All data nodes in data trees are connected with their schema node - libyang is not able to represent data of an |
| 327 | * unknown schema. |
| 328 | * |
| 329 | * By default, the represented data are supposed to represent a full YANG datastore content. So if a schema declares |
| 330 | * some mandatory nodes, despite configuration or status, the data are supposed to be present in the data tree being |
| 331 | * loaded or validated. However, it is possible to specify other kinds of data (see @ref parseroptions) allowing some |
| 332 | * exceptions to the validation process. |
| 333 | * |
| 334 | * Data validation is performed implicitly to the input data processed by the parser (\b lyd_parse_*() functions) and |
| 335 | * on demand via the lyd_validate() function. The lyd_validate() is supposed to be used when a (complex or simple) |
| 336 | * change is done on the data tree (via a combination of \b lyd_change_*(), \b lyd_insert*(), \b lyd_new*(), |
| 337 | * lyd_unlink() and lyd_free() functions). |
| 338 | * |
| 339 | * - @subpage howtodataparsers |
| 340 | * - @subpage howtodatamanipulators |
| 341 | * - @subpage howtodataprinters |
| 342 | * |
| 343 | * \note API for this group of functions is described in the [Data Instances module](@ref datatree). |
| 344 | * |
| 345 | * Functions List (not assigned to above subsections) |
| 346 | * -------------------------------------------------- |
| 347 | * - lyd_get_node() |
| 348 | */ |
| 349 | |
| 350 | /** |
| 351 | * @page howtodataparsers Parsing Data |
| 352 | * |
| 353 | * Data parser allows to read instances from a specific format. libyang supports the following data formats: |
| 354 | * |
| 355 | * - XML |
| 356 | * |
| 357 | * Original data format used in NETCONF protocol. XML mapping is part of the YANG specification |
| 358 | * ([RFC 6020](http://tools.ietf.org/html/rfc6020)). |
| 359 | * |
| 360 | * - JSON |
| 361 | * |
| 362 | * The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG |
| 363 | * can be found in [this draft](https://tools.ietf.org/html/draft-ietf-netmod-yang-json-05). |
| 364 | * |
| 365 | * Besides the format of input data, the parser functions accepts additional [options](@ref parseroptions) to specify |
| 366 | * how the input data should be processed. |
| 367 | * |
| 368 | * In contrast to the schema parser, data parser also accepts empty input data if such an empty data tree is valid |
| 369 | * according to the schemas in the libyang context. |
| 370 | * |
| 371 | * In case of XML input data, there is one additional way to parse input data. Besides parsing the data from a string |
| 372 | * in memory or a file, caller is able to build an XML tree using [libyang XML parser](@ref howtoxml) and then use |
| 373 | * this tree (or a part of it) as input to the lyd_parse_xml() function. |
| 374 | * |
| 375 | * Functions List |
| 376 | * -------------- |
| 377 | * - lyd_parse_data() |
| 378 | * - lyd_parse_fd() |
| 379 | * - lyd_parse_path() |
| 380 | * - lyd_parse_xml() |
| 381 | */ |
| 382 | |
| 383 | /** |
| 384 | * @page howtodatamanipulators Manipulating Data |
| 385 | * |
| 386 | * There are many functions to create or modify an existing data tree. You can add new nodes, reconnect nodes from |
| 387 | * one tree to another (or e.g. from one list instance to another) or remove nodes. The functions doesn't allow you |
| 388 | * to put a node to a wrong place (by checking the module), but not all validation checks can be made directly |
| 389 | * (or you have to make a valid change by multiple tree modifications) when the tree is being changed. Therefore, |
| 390 | * there is lyd_validate() function supposed to be called to make sure that the current data tree is valid. Note, |
| 391 | * that not calling this function after the performed changes can cause failure of various libyang functions later. |
| 392 | * |
| 393 | * Also remember, that when you are creating/inserting a node, all the objects in that operation must belong to the |
| 394 | * same context. |
| 395 | * |
| 396 | * Modifying the single data tree in multiple threads is not safe. |
| 397 | * |
| 398 | * Functions List |
| 399 | * -------------- |
| 400 | * - lyd_dup() |
| 401 | * - lyd_change_leaf() |
| 402 | * - lyd_insert() |
| 403 | * - lyd_insert_before() |
| 404 | * - lyd_insert_after() |
| 405 | * - lyd_insert_attr() |
| 406 | * - lyd_new() |
| 407 | * - lyd_new_anyxml() |
| 408 | * - lyd_new_leaf() |
| 409 | * - lyd_output_new() |
| 410 | * - lyd_output_new_anyxml() |
| 411 | * - lyd_output_new_leaf() |
| 412 | * - lyd_unlink() |
| 413 | * - lyd_free() |
| 414 | * - lyd_free_attr() |
| 415 | * - lyd_free_withsiblings() |
| 416 | * - lyd_validate() |
| 417 | */ |
| 418 | |
| 419 | /** |
| 420 | * @page howtodataprinters Printing Data |
| 421 | * |
| 422 | * Schema printers allows to serialize internal representation of a schema module in a specific format. libyang |
| 423 | * supports the following schema formats for printing: |
| 424 | * |
| 425 | * - XML |
| 426 | * |
| 427 | * Basic format as specified in rules of mapping YANG modeled data to XML in |
| 428 | * [RFC 6020](http://tools.ietf.org/html/rfc6020). It is possible to specify if |
| 429 | * the indentation will be used. |
| 430 | * |
| 431 | * - JSON |
| 432 | * |
| 433 | * The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG |
| 434 | * can be found in [this draft](https://tools.ietf.org/html/draft-ietf-netmod-yang-json-05). |
| 435 | * |
| 436 | * Printer functions allow to print to the different outputs including a callback function which allows caller |
| 437 | * to have a full control of the output data - libyang passes to the callback a private argument (some internal |
| 438 | * data provided by a caller of lyd_print_clb()), string buffer and number of characters to print. Note that the |
| 439 | * callback is supposed to be called multiple times during the lyd_print_clb() execution. |
| 440 | * |
| 441 | * Functions List |
| 442 | * -------------- |
| 443 | * - lyd_print_mem() |
| 444 | * - lyd_print_fd() |
| 445 | * - lyd_print_file() |
| 446 | * - lyd_print_clb() |
| 447 | */ |
| 448 | |
| 449 | /** |
| 450 | * @page howtoxml libyang XML Support |
| 451 | * |
| 452 | * libyang XML parser is able to parse XML documents used to represent data modeled by YANG. Therefore, there are |
| 453 | * some limitations in comparison to a full-featured XML parsers: |
| 454 | * - comments are ignored |
| 455 | * - Doctype declaration is ignored |
| 456 | * - CData sections are ignored |
| 457 | * - Process Instructions (PI) are ignored |
| 458 | * |
| 459 | * The API is designed to almost only read-only access. You can simply load XML document, go through the tree as |
| 460 | * you wish and dump the tree to an output. The only "write" functions are lyxml_free() and lyxml_unlink() to remove |
| 461 | * part of the tree or to unlink (separate) a subtree. |
| 462 | * |
| 463 | * XML parser is also used internally by libyang for parsing YIN schemas and data instances in XML format. |
| 464 | * |
| 465 | * \note API for this group of functions is described in the [XML Parser module](@ref xmlparser). |
| 466 | * |
| 467 | * Functions List |
| 468 | * -------------- |
| 469 | * - lyxml_read_data() |
| 470 | * - lyxml_read_path() |
| 471 | * - lyxml_get_attr() |
| 472 | * - lyxml_get_ns() |
| 473 | * - lyxml_dump_mem() |
| 474 | * - lyxml_dump_fd() |
| 475 | * - lyxml_dump_file() |
| 476 | * - lyxml_dump_clb() |
| 477 | * - lyxml_unlink() |
| 478 | * - lyxml_free() |
| 479 | */ |
| 480 | |
| 481 | /** |
| 482 | * @page howtothreads libyang in Threads |
| 483 | * |
| 484 | * libyang can be used in multithreaded application keeping in mind the following rules: |
| 485 | * - libyang context manipulation (adding new schemas) is not thread safe and it is supposed to be done in a main |
| 486 | * thread before any other work with context, schemas or data instances. And destroying the context is supposed to |
| 487 | * be done when no other thread accesses context, schemas nor data trees |
| 488 | * - Data parser (\b lyd_parse*() functions) can be used simultaneously in multiple threads (also the returned |
| 489 | * #ly_errno is thread safe). |
| 490 | * - Modifying (lyd_new(), lyd_insert(), lyd_unlink(), lyd_free() and many other functions) a single data tree is not |
| 491 | * thread safe. |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 492 | */ |
Radek Krejci | 94ca54b | 2015-07-08 15:48:47 +0200 | [diff] [blame] | 493 | |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 494 | /** |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 495 | * |
| 496 | * @page howtologger Logger |
| 497 | * |
| 498 | * There are 4 verbosity levels defined as ::LY_LOG_LEVEL. The level can be |
| 499 | * changed by the ly_verb() function. By default, the verbosity level is |
| 500 | * set to #LY_LLERR value. |
| 501 | * |
| 502 | * In case the logger has an error message (LY_LLERR) to print, also an error |
| 503 | * code is recorded in extern ly_errno variable. Possible values are of type |
| 504 | * ::LY_ERR. |
| 505 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 506 | * \note API for this group of functions is described in the [logger module](@ref logger). |
| 507 | * |
| 508 | * Functions List |
| 509 | * -------------- |
| 510 | * - ly_verb() |
| 511 | * - ly_set_log_clb() |
| 512 | * - ly_get_log_clb() |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 513 | */ |
| 514 | |
| 515 | /** |
| 516 | * @defgroup context Context |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 517 | * @{ |
| 518 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 519 | * Structures and functions to manipulate with the libyang "containers". The \em context concept allows callers |
| 520 | * to work in environments with different sets of YANG schemas. More detailed information can be found at |
| 521 | * @ref howtocontext page. |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 522 | */ |
| 523 | |
| 524 | /** |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 525 | * @brief libyang context handler. |
| 526 | */ |
| 527 | struct ly_ctx; |
| 528 | |
| 529 | /** |
| 530 | * @brief Create libyang context |
| 531 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 532 | * 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] | 533 | * to work with a single context in which libyang is holding all schemas (and other internal |
| 534 | * information) according to which the data trees will be processed and validated. So, the schema |
| 535 | * trees are tightly connected with the specific context and they are held by the context internally |
| 536 | * - caller does not need to keep pointers to the schemas returned by lys_parse(), context knows |
| 537 | * about them. The data trees created with lyd_parse() are still connected with the specific context, |
| 538 | * but they are not internally held by the context. The data tree just points and lean on some data |
| 539 | * held by the context (schema tree, string dictionary, etc.). Therefore, in case of data trees, caller |
| 540 | * is supposed to keep pointers returned by the lyd_parse() and manage the data tree on its own. This |
| 541 | * also affects the number of instances of both tree types. While you can have only one instance of |
| 542 | * 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] | 543 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 544 | * @param[in] search_dir Directory where libyang will search for the imported or included modules |
| 545 | * and submodules. If no such directory is available, NULL is accepted. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 546 | * |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 547 | * @return Pointer to the created libyang context, NULL in case of error. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 548 | */ |
| 549 | struct ly_ctx *ly_ctx_new(const char *search_dir); |
| 550 | |
| 551 | /** |
Michal Vasko | 60ba9a6 | 2015-07-03 14:42:31 +0200 | [diff] [blame] | 552 | * @brief Change the search path in libyang context |
| 553 | * |
| 554 | * @param[in] ctx Context to be modified. |
| 555 | * @param[in] search_dir New search path to replace the current one in ctx. |
| 556 | */ |
| 557 | void ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir); |
| 558 | |
| 559 | /** |
Radek Krejci | 5a79757 | 2015-10-21 15:45:45 +0200 | [diff] [blame] | 560 | * @brief Get current value of the search path in libyang context |
| 561 | * |
| 562 | * @param[in] ctx Context to query. |
| 563 | * @return Current value of the search path. |
| 564 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 565 | const char *ly_ctx_get_searchdir(const struct ly_ctx *ctx); |
Radek Krejci | 5a79757 | 2015-10-21 15:45:45 +0200 | [diff] [blame] | 566 | |
| 567 | /** |
Radek Krejci | 7ab2515 | 2015-08-07 14:48:45 +0200 | [diff] [blame] | 568 | * @brief Get data of an internal ietf-yang-library module. |
| 569 | * |
| 570 | * @param[in] ctx Context with the modules. |
| 571 | * @return Root data node corresponding to the model, NULL on error. |
| 572 | * Caller is responsible for freeing the returned data tree using lyd_free(). |
| 573 | */ |
| 574 | struct lyd_node *ly_ctx_info(struct ly_ctx *ctx); |
| 575 | |
| 576 | /** |
Radek Krejci | 96a10da | 2015-07-30 11:00:14 +0200 | [diff] [blame] | 577 | * @brief Get the names of the loaded modules. |
| 578 | * |
| 579 | * @param[in] ctx Context with the modules. |
| 580 | * @return NULL-terminated array of the module names, |
| 581 | * NULL on error. The returned array must be freed by the caller, do not free |
| 582 | * names in the array. Also remember that the names will be freed with freeing |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 583 | * the context. |
Radek Krejci | 96a10da | 2015-07-30 11:00:14 +0200 | [diff] [blame] | 584 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 585 | const char **ly_ctx_get_module_names(const struct ly_ctx *ctx); |
Radek Krejci | 96a10da | 2015-07-30 11:00:14 +0200 | [diff] [blame] | 586 | |
| 587 | /** |
| 588 | * @brief Get the names of the loaded submodules of the specified module. |
| 589 | * |
| 590 | * @param[in] ctx Context with the modules. |
| 591 | * @param[in] module_name Name of the parent module. |
| 592 | * @return NULL-terminated array of submodule names of the parent module, |
| 593 | * NULL on error. The returned array must be freed by the caller, do not free |
| 594 | * names in the array. Also remember that the names will be freed with freeing |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 595 | * the context. |
Radek Krejci | 96a10da | 2015-07-30 11:00:14 +0200 | [diff] [blame] | 596 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 597 | const char **ly_ctx_get_submodule_names(const struct ly_ctx *ctx, const char *module_name); |
Radek Krejci | 96a10da | 2015-07-30 11:00:14 +0200 | [diff] [blame] | 598 | |
| 599 | /** |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 600 | * @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] | 601 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 602 | * @param[in] ctx Context to work in. |
| 603 | * @param[in] name Name of the YANG module to get. |
Radek Krejci | f647e61 | 2015-07-30 11:36:07 +0200 | [diff] [blame] | 604 | * @param[in] revision Optional revision date of the YANG module to get. If not specified, |
| 605 | * the schema in the newest revision is returned if any. |
| 606 | * @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] | 607 | * revision requirements is present in the context. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 608 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 609 | 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] | 610 | |
| 611 | /** |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 612 | * @brief Try to find the model in the searchpath of \p ctx and load it into it. If custom missing |
| 613 | * module callback is set, it is used instead. |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 614 | * |
| 615 | * @param[in] ctx Context to add to. |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 616 | * @param[in] name Name of the module to load. |
| 617 | * @param[in] revision Optional revision date of the module. If not specified, it is |
| 618 | * assumed that there is only one model revision in the searchpath (the first matching file |
| 619 | * is parsed). |
| 620 | * @return Pointer to the data model structure, NULL if not found or some error occured. |
| 621 | */ |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 622 | const struct lys_module *ly_ctx_load_module(struct ly_ctx *ctx, const char *name, const char *revision); |
| 623 | |
| 624 | /** |
| 625 | * @brief Callback for retrieving missing included or imported models in a custom way. |
| 626 | * |
| 627 | * @param[in] name Missing module name. |
| 628 | * @param[in] revision Optional missing module revision. |
| 629 | * @param[in] user_data User-supplied callback data. |
| 630 | * @param[out] format Format of the returned module data. |
| 631 | * @param[out] free_module_data Optional callback for freeing the returned module data. If not set, free() is used. |
| 632 | * @return Requested module data or NULL on error. |
| 633 | */ |
| 634 | typedef char *(*ly_module_clb)(const char *name, const char *revision, void *user_data, LYS_INFORMAT *format, |
| 635 | void (**free_module_data)(char *model_data)); |
| 636 | |
| 637 | /** |
| 638 | * @brief Set missing include or import model callback. |
| 639 | * |
| 640 | * @param[in] ctx Context that will use this callback. |
| 641 | * @param[in] clb Callback responsible for returning a missing model. |
| 642 | * @param[in] user_data Arbitrary data that will always be passed to the callback \p clb. |
| 643 | */ |
| 644 | void ly_ctx_set_module_clb(struct ly_ctx *ctx, ly_module_clb clb, void *user_data); |
| 645 | |
| 646 | /** |
| 647 | * @brief Get the custom callback for missing module retrieval. |
| 648 | * |
| 649 | * @param[in] ctx Context to read from. |
| 650 | * @param[in] user_data Optional pointer for getting the user-supplied callbck data. |
| 651 | * @return Custom user missing module callback or NULL if not set. |
| 652 | */ |
| 653 | 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] | 654 | |
| 655 | /** |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 656 | * @brief Get pointer to the schema tree of the module of the specified namespace |
| 657 | * |
| 658 | * @param[in] ctx Context to work in. |
| 659 | * @param[in] ns Namespace of the YANG module to get. |
| 660 | * @param[in] revision Optional revision date of the YANG module to get. If not specified, |
| 661 | * the schema in the newest revision is returned if any. |
| 662 | * @return Pointer to the data model structure, NULL if no schema following the namespace and |
| 663 | * revision requirements is present in the context. |
| 664 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 665 | 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] | 666 | |
| 667 | /** |
Michal Vasko | 7bf0688 | 2015-07-03 15:33:56 +0200 | [diff] [blame] | 668 | * @brief Get submodule from the context's search dir. |
| 669 | * |
| 670 | * @param[in] module Parent (belongs-to) module. |
| 671 | * @param[in] name Name of the YANG submodule to get. |
| 672 | * @param[in] revision Optional revision date of the YANG submodule to get. If |
| 673 | * not specified, the newest revision is returned (TODO). |
Michal Vasko | 7bf0688 | 2015-07-03 15:33:56 +0200 | [diff] [blame] | 674 | * @return Pointer to the data model structure. |
| 675 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 676 | const struct lys_submodule *ly_ctx_get_submodule(const struct lys_module *module, const char *name, |
| 677 | const char *revision); |
Michal Vasko | 7bf0688 | 2015-07-03 15:33:56 +0200 | [diff] [blame] | 678 | |
| 679 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 680 | * @brief Free all internal structures of the specified context. |
| 681 | * |
| 682 | * The function should be used before terminating the application to destroy |
| 683 | * and free all structures internally used by libyang. If the caller uses |
| 684 | * multiple contexts, the function should be called for each used context. |
| 685 | * |
| 686 | * All instance data are supposed to be freed before destroying the context. |
| 687 | * Data models are destroyed automatically as part of ly_ctx_destroy() call. |
| 688 | * |
| 689 | * @param[in] ctx libyang context to destroy |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 690 | */ |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 691 | void ly_ctx_destroy(struct ly_ctx *ctx); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 692 | |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 693 | /**@} context */ |
| 694 | |
| 695 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 696 | * @defgroup nodeset Tree nodes set |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 697 | * @ingroup datatree |
| 698 | * @ingroup schematree |
| 699 | * @{ |
| 700 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 701 | * Structure and functions to hold and manipulate with sets of nodes from schema or data trees. |
| 702 | */ |
| 703 | |
| 704 | /** |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 705 | * @brief Structure to hold a set of (not necessary somehow connected) ::lyd_node or ::lys_node objects. |
| 706 | * Caller is supposed to not mix the type of objects added to the set and according to its knowledge about |
| 707 | * the set content, it is supposed to access the set via the sset, dset or set members of the structure. |
| 708 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 709 | * To free the structure, use ly_set_free() function, to manipulate with the structure, use other |
| 710 | * ly_set_* functions. |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 711 | */ |
| 712 | struct ly_set { |
| 713 | unsigned int size; /**< allocated size of the set array */ |
| 714 | unsigned int number; /**< number of elements in (used size of) the set array */ |
| 715 | union { |
| 716 | struct lys_node **sset; /**< array of pointers to a ::lys_node objects */ |
| 717 | struct lyd_node **dset; /**< array of pointers to a ::lyd_node objects */ |
| 718 | void **set; /**< dummy array for generic work */ |
| 719 | }; |
| 720 | }; |
| 721 | |
| 722 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 723 | * @brief Create and initiate new ::ly_set structure. |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 724 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 725 | * @return Created ::ly_set structure or NULL in case of error. |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 726 | */ |
| 727 | struct ly_set *ly_set_new(void); |
| 728 | |
| 729 | /** |
| 730 | * @brief Add a ::lyd_node or ::lys_node object into the set |
| 731 | * |
| 732 | * @param[in] set Set where the \p node will be added. |
| 733 | * @param[in] node The ::lyd_node or ::lys_node object to be added into the \p set; |
| 734 | * @return 0 on success |
| 735 | */ |
| 736 | int ly_set_add(struct ly_set *set, void *node); |
| 737 | |
| 738 | /** |
| 739 | * @brief Remove a ::lyd_node or ::lys_node object from the set. |
| 740 | * |
| 741 | * Note that after removing a node from a set, indexes of other nodes in the set can change |
| 742 | * (the last object is placed instead of the removed object). |
| 743 | * |
| 744 | * @param[in] set Set from which the \p node will be removed. |
| 745 | * @param[in] node The ::lyd_node or ::lys_node object to be removed from the \p set; |
| 746 | * @return 0 on success |
| 747 | */ |
| 748 | int ly_set_rm(struct ly_set *set, void *node); |
| 749 | |
| 750 | /** |
| 751 | * @brief Remove a ::lyd_node or ::lys_node object from the set index. |
| 752 | * |
| 753 | * Note that after removing a node from a set, indexes of other nodes in the set can change |
| 754 | * (the last object is placed instead of the removed object). |
| 755 | * |
| 756 | * @param[in] set Set from which a node will be removed. |
| 757 | * @param[in] index Index of the ::lyd_node or ::lys_node object in the \p set to be removed from the \p set; |
| 758 | * @return 0 on success |
| 759 | */ |
| 760 | int ly_set_rm_index(struct ly_set *set, unsigned int index); |
| 761 | |
| 762 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 763 | * @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] | 764 | * |
| 765 | * @param[in] set The set to be freed. |
| 766 | */ |
| 767 | void ly_set_free(struct ly_set *set); |
| 768 | |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 769 | /**@} nodeset */ |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 770 | |
| 771 | /** |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame] | 772 | * @defgroup printerflags Printer flags |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 773 | * @ingroup datatree |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame] | 774 | * |
| 775 | * Validity flags for data nodes. |
| 776 | * |
| 777 | * @{ |
| 778 | */ |
| 779 | #define LYP_WITHSIBLINGS 0x01 /**< Flag for printing also the (following) sibling nodes of the data node. */ |
| 780 | |
| 781 | /** |
| 782 | * @} |
| 783 | */ |
| 784 | |
| 785 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 786 | * @defgroup logger Logger |
| 787 | * @{ |
| 788 | * |
| 789 | * Publicly visible functions and values of the libyang logger. For more |
| 790 | * information, see \ref howtologger. |
| 791 | */ |
| 792 | |
| 793 | /** |
| 794 | * @typedef LY_LOG_LEVEL |
| 795 | * @brief Verbosity levels of the libyang logger. |
| 796 | */ |
| 797 | typedef enum { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 798 | LY_LLERR, /**< Print only error messages. */ |
| 799 | LY_LLWRN, /**< Print error and warning messages. */ |
| 800 | LY_LLVRB, /**< Besides errors and warnings, print some other verbose messages. */ |
| 801 | LY_LLDBG /**< Print all messages including some development debug messages. */ |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 802 | } LY_LOG_LEVEL; |
| 803 | |
| 804 | /** |
| 805 | * @brief Set logger verbosity level. |
| 806 | * @param[in] level Verbosity level. |
| 807 | */ |
| 808 | void ly_verb(LY_LOG_LEVEL level); |
| 809 | |
| 810 | /** |
Michal Vasko | f1d62cf | 2015-12-07 13:17:11 +0100 | [diff] [blame] | 811 | * @brief Set logger callback. |
| 812 | * @param[in] clb Logging callback. |
| 813 | */ |
| 814 | void ly_set_log_clb(void (*clb)(LY_LOG_LEVEL, const char *)); |
| 815 | |
| 816 | /** |
| 817 | * @brief Get logger callback. |
| 818 | * @return Logger callback (can be NULL). |
| 819 | */ |
| 820 | void (*ly_get_log_clb(void))(LY_LOG_LEVEL, const char *); |
| 821 | |
| 822 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 823 | * @typedef LY_ERR |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 824 | * @brief libyang's error codes available via ly_errno extern variable. |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 825 | * @ingroup logger |
| 826 | */ |
| 827 | typedef enum { |
Radek Krejci | ae6817a | 2015-08-10 14:02:06 +0200 | [diff] [blame] | 828 | 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] | 829 | LY_EMEM, /**< Memory allocation failure */ |
| 830 | LY_ESYS, /**< System call failure */ |
| 831 | LY_EINVAL, /**< Invalid value */ |
| 832 | LY_EINT, /**< Internal error */ |
| 833 | LY_EVALID /**< Validation failure */ |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 834 | } LY_ERR; |
Radek Krejci | 7d9f46a | 2016-01-29 13:53:18 +0100 | [diff] [blame] | 835 | |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 836 | /** |
Radek Krejci | 7d9f46a | 2016-01-29 13:53:18 +0100 | [diff] [blame] | 837 | * @cond INTERNAL |
| 838 | * Function to get address of global `ly_errno' variable. |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 839 | */ |
Radek Krejci | 7d9f46a | 2016-01-29 13:53:18 +0100 | [diff] [blame] | 840 | LY_ERR *ly_errno_location(void); |
| 841 | |
| 842 | /** |
| 843 | * @endcond INTERNAL |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame^] | 844 | * @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] | 845 | */ |
| 846 | #define ly_errno (*ly_errno_location()) |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 847 | |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 848 | /**@} logger */ |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 849 | |
Radek Krejci | 39d8d0d | 2015-08-17 13:42:45 +0200 | [diff] [blame] | 850 | #ifdef __cplusplus |
| 851 | } |
| 852 | #endif |
| 853 | |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 854 | #endif /* LY_LIBYANG_H_ */ |