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