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