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 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in |
| 15 | * the documentation and/or other materials provided with the |
| 16 | * distribution. |
| 17 | * 3. Neither the name of the Company nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this |
| 19 | * software without specific prior written permission. |
| 20 | */ |
| 21 | |
| 22 | #ifndef LY_LIBYANG_H_ |
| 23 | #define LY_LIBYANG_H_ |
| 24 | |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 27 | #include "tree_schema.h" |
| 28 | #include "tree_data.h" |
Radek Krejci | c6704c8 | 2015-10-06 11:12:45 +0200 | [diff] [blame] | 29 | #include "xml.h" |
Radek Krejci | 41912fe | 2015-10-22 10:22:12 +0200 | [diff] [blame] | 30 | #include "dict.h" |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 31 | |
Radek Krejci | 39d8d0d | 2015-08-17 13:42:45 +0200 | [diff] [blame] | 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 36 | /** |
| 37 | * @page howto How To ... |
| 38 | * |
| 39 | * - @subpage howtocontext |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 40 | * - @subpage howtoschemas |
| 41 | * - @subpage howtodata |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 42 | * - @subpage howtologger |
| 43 | */ |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 44 | |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 45 | /** @page howtocontext Context |
| 46 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 47 | * 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] | 48 | * |
| 49 | * The first step in libyang is to create a new context using ly_ctx_new(). It returns a handler |
| 50 | * used in the following work. |
| 51 | * |
| 52 | * When creating a new context, search dir can be specified (NULL is accepted) to provide directory |
| 53 | * where libyang will automatically search for schemas being imported or included. The search path |
| 54 | * can be later changed via ly_ctx_set_searchdir() function. Before exploring the specified search |
| 55 | * dir, libyang tries to get imported and included schemas from the current working directory first. |
| 56 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 57 | * Schemas are added into the context using [parser functions](@ref parsers) - lys_parse() or lys_read(). |
| 58 | * Note, that parser functions for schemas have \b lys_ prefix while instance data parser functions have |
| 59 | * \b lyd_ prefix. |
| 60 | * |
Radek Krejci | f647e61 | 2015-07-30 11:36:07 +0200 | [diff] [blame] | 61 | * Context can hold multiple revisons of the same schema. |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 62 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 63 | * Context holds all modules and their submodules internally. The list of available module names is |
| 64 | * provided via ly_ctx_get_module_names() functions. Similarly, caller can get also a list of submodules |
| 65 | * names of a specific module using ly_ctx_get_submodule_names() function. The returned names can be |
| 66 | * subsequently used to get the (sub)module structures using ly_ctx_get_module() and ly_ctx_get_submodule(). |
| 67 | * |
| 68 | * Modules held by a context cannot be removed one after one. The only way how to \em change modules in the |
| 69 | * context is to create a new context and remove the old one. To remove a context, there is ly_ctx_destroy() |
| 70 | * function. |
| 71 | * |
| 72 | * \note API for this group of functions is available in the [context module](@ref context). |
| 73 | * |
| 74 | */ |
| 75 | |
| 76 | /** |
| 77 | * @page howtoschemas Schemas |
| 78 | * |
| 79 | * Schema is an internal libyang's representation of a YANG data model. Each schema is connected with |
| 80 | * its [context](@ref howtocontext) and loaded using [parser functions](@ref parsers). It means, that |
| 81 | * the schema cannot be created (nor changed) programatically. In libyang, schemas are used only to |
| 82 | * access data model definitions. |
| 83 | * |
| 84 | * \note There are many functions to access information from the schema trees. Details are available in |
| 85 | * the [Schema Tree module](@ref schematree). |
| 86 | * |
| 87 | * YANG Features Manipulation |
| 88 | * -------------------------- |
| 89 | * |
| 90 | * The group of functions prefixed by \b lys_features_ are used to access and manipulate with the schema's |
| 91 | * features. |
| 92 | * |
| 93 | * The first two functions are used to access information about the features in the schema. |
| 94 | * lys_features_list() provides list of all features defined in the specific schema and its |
| 95 | * submodules. Optionally, it can also provides information about the state of all features. |
| 96 | * Alternatively, caller can use lys_features_state() function to get state of one specific |
| 97 | * feature. |
| 98 | * |
| 99 | * The remaining two functions, lys_features_enable() and lys_features_disable(), are used |
| 100 | * to enable and disable the specific feature. By default, when the module is loaded by libyang |
| 101 | * parser, all features are disabled. |
| 102 | * |
| 103 | * Note, that feature's state can affect some of the output formats (e.g. Tree format). |
| 104 | * |
| 105 | */ |
| 106 | |
| 107 | /** |
| 108 | * @page howtodata Data Instances |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 109 | * |
| 110 | */ |
Radek Krejci | 94ca54b | 2015-07-08 15:48:47 +0200 | [diff] [blame] | 111 | |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 112 | /** |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 113 | * |
| 114 | * @page howtologger Logger |
| 115 | * |
| 116 | * There are 4 verbosity levels defined as ::LY_LOG_LEVEL. The level can be |
| 117 | * changed by the ly_verb() function. By default, the verbosity level is |
| 118 | * set to #LY_LLERR value. |
| 119 | * |
| 120 | * In case the logger has an error message (LY_LLERR) to print, also an error |
| 121 | * code is recorded in extern ly_errno variable. Possible values are of type |
| 122 | * ::LY_ERR. |
| 123 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 124 | * \note API for this group of functions is available in the [logger module](@ref logger). |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 125 | */ |
| 126 | |
| 127 | /** |
| 128 | * @defgroup context Context |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 129 | * @{ |
| 130 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 131 | * Structures and functions to manipulate with the libyang "containers". The \em context concept allows callers |
| 132 | * to work in environments with different sets of YANG schemas. More detailed information can be found at |
| 133 | * @ref howtocontext page. |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 134 | */ |
| 135 | |
| 136 | /** |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 137 | * @brief libyang context handler. |
| 138 | */ |
| 139 | struct ly_ctx; |
| 140 | |
| 141 | /** |
| 142 | * @brief Create libyang context |
| 143 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 144 | * 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] | 145 | * to work with a single context in which libyang is holding all schemas (and other internal |
| 146 | * information) according to which the data trees will be processed and validated. So, the schema |
| 147 | * trees are tightly connected with the specific context and they are held by the context internally |
| 148 | * - caller does not need to keep pointers to the schemas returned by lys_parse(), context knows |
| 149 | * about them. The data trees created with lyd_parse() are still connected with the specific context, |
| 150 | * but they are not internally held by the context. The data tree just points and lean on some data |
| 151 | * held by the context (schema tree, string dictionary, etc.). Therefore, in case of data trees, caller |
| 152 | * is supposed to keep pointers returned by the lyd_parse() and manage the data tree on its own. This |
| 153 | * also affects the number of instances of both tree types. While you can have only one instance of |
| 154 | * 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] | 155 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 156 | * @param[in] search_dir Directory where libyang will search for the imported or included modules |
| 157 | * and submodules. If no such directory is available, NULL is accepted. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 158 | * |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 159 | * @return Pointer to the created libyang context, NULL in case of error. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 160 | */ |
| 161 | struct ly_ctx *ly_ctx_new(const char *search_dir); |
| 162 | |
| 163 | /** |
Michal Vasko | 60ba9a6 | 2015-07-03 14:42:31 +0200 | [diff] [blame] | 164 | * @brief Change the search path in libyang context |
| 165 | * |
| 166 | * @param[in] ctx Context to be modified. |
| 167 | * @param[in] search_dir New search path to replace the current one in ctx. |
| 168 | */ |
| 169 | void ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir); |
| 170 | |
| 171 | /** |
Radek Krejci | 5a79757 | 2015-10-21 15:45:45 +0200 | [diff] [blame] | 172 | * @brief Get current value of the search path in libyang context |
| 173 | * |
| 174 | * @param[in] ctx Context to query. |
| 175 | * @return Current value of the search path. |
| 176 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 177 | const char *ly_ctx_get_searchdir(const struct ly_ctx *ctx); |
Radek Krejci | 5a79757 | 2015-10-21 15:45:45 +0200 | [diff] [blame] | 178 | |
| 179 | /** |
Radek Krejci | 7ab2515 | 2015-08-07 14:48:45 +0200 | [diff] [blame] | 180 | * @brief Get data of an internal ietf-yang-library module. |
| 181 | * |
| 182 | * @param[in] ctx Context with the modules. |
| 183 | * @return Root data node corresponding to the model, NULL on error. |
| 184 | * Caller is responsible for freeing the returned data tree using lyd_free(). |
| 185 | */ |
| 186 | struct lyd_node *ly_ctx_info(struct ly_ctx *ctx); |
| 187 | |
| 188 | /** |
Radek Krejci | 96a10da | 2015-07-30 11:00:14 +0200 | [diff] [blame] | 189 | * @brief Get the names of the loaded modules. |
| 190 | * |
| 191 | * @param[in] ctx Context with the modules. |
| 192 | * @return NULL-terminated array of the module names, |
| 193 | * NULL on error. The returned array must be freed by the caller, do not free |
| 194 | * 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] | 195 | * the context. |
Radek Krejci | 96a10da | 2015-07-30 11:00:14 +0200 | [diff] [blame] | 196 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 197 | const char **ly_ctx_get_module_names(const struct ly_ctx *ctx); |
Radek Krejci | 96a10da | 2015-07-30 11:00:14 +0200 | [diff] [blame] | 198 | |
| 199 | /** |
| 200 | * @brief Get the names of the loaded submodules of the specified module. |
| 201 | * |
| 202 | * @param[in] ctx Context with the modules. |
| 203 | * @param[in] module_name Name of the parent module. |
| 204 | * @return NULL-terminated array of submodule names of the parent module, |
| 205 | * NULL on error. The returned array must be freed by the caller, do not free |
| 206 | * 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] | 207 | * the context. |
Radek Krejci | 96a10da | 2015-07-30 11:00:14 +0200 | [diff] [blame] | 208 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 209 | 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] | 210 | |
| 211 | /** |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 212 | * @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] | 213 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 214 | * @param[in] ctx Context to work in. |
| 215 | * @param[in] name Name of the YANG module to get. |
Radek Krejci | f647e61 | 2015-07-30 11:36:07 +0200 | [diff] [blame] | 216 | * @param[in] revision Optional revision date of the YANG module to get. If not specified, |
| 217 | * the schema in the newest revision is returned if any. |
| 218 | * @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] | 219 | * revision requirements is present in the context. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 220 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 221 | 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] | 222 | |
| 223 | /** |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 224 | * @brief Try to find the model in the searchpath of \p ctx and load it into it. If custom missing |
| 225 | * module callback is set, it is used instead. |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 226 | * |
| 227 | * @param[in] ctx Context to add to. |
Michal Vasko | 8246596 | 2015-11-10 11:03:11 +0100 | [diff] [blame] | 228 | * @param[in] name Name of the module to load. |
| 229 | * @param[in] revision Optional revision date of the module. If not specified, it is |
| 230 | * assumed that there is only one model revision in the searchpath (the first matching file |
| 231 | * is parsed). |
| 232 | * @return Pointer to the data model structure, NULL if not found or some error occured. |
| 233 | */ |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 234 | const struct lys_module *ly_ctx_load_module(struct ly_ctx *ctx, const char *name, const char *revision); |
| 235 | |
| 236 | /** |
| 237 | * @brief Callback for retrieving missing included or imported models in a custom way. |
| 238 | * |
| 239 | * @param[in] name Missing module name. |
| 240 | * @param[in] revision Optional missing module revision. |
| 241 | * @param[in] user_data User-supplied callback data. |
| 242 | * @param[out] format Format of the returned module data. |
| 243 | * @param[out] free_module_data Optional callback for freeing the returned module data. If not set, free() is used. |
| 244 | * @return Requested module data or NULL on error. |
| 245 | */ |
| 246 | typedef char *(*ly_module_clb)(const char *name, const char *revision, void *user_data, LYS_INFORMAT *format, |
| 247 | void (**free_module_data)(char *model_data)); |
| 248 | |
| 249 | /** |
| 250 | * @brief Set missing include or import model callback. |
| 251 | * |
| 252 | * @param[in] ctx Context that will use this callback. |
| 253 | * @param[in] clb Callback responsible for returning a missing model. |
| 254 | * @param[in] user_data Arbitrary data that will always be passed to the callback \p clb. |
| 255 | */ |
| 256 | void ly_ctx_set_module_clb(struct ly_ctx *ctx, ly_module_clb clb, void *user_data); |
| 257 | |
| 258 | /** |
| 259 | * @brief Get the custom callback for missing module retrieval. |
| 260 | * |
| 261 | * @param[in] ctx Context to read from. |
| 262 | * @param[in] user_data Optional pointer for getting the user-supplied callbck data. |
| 263 | * @return Custom user missing module callback or NULL if not set. |
| 264 | */ |
| 265 | 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] | 266 | |
| 267 | /** |
Radek Krejci | fd4e6e3 | 2015-08-10 15:00:51 +0200 | [diff] [blame] | 268 | * @brief Get pointer to the schema tree of the module of the specified namespace |
| 269 | * |
| 270 | * @param[in] ctx Context to work in. |
| 271 | * @param[in] ns Namespace of the YANG module to get. |
| 272 | * @param[in] revision Optional revision date of the YANG module to get. If not specified, |
| 273 | * the schema in the newest revision is returned if any. |
| 274 | * @return Pointer to the data model structure, NULL if no schema following the namespace and |
| 275 | * revision requirements is present in the context. |
| 276 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 277 | 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] | 278 | |
| 279 | /** |
Michal Vasko | 7bf0688 | 2015-07-03 15:33:56 +0200 | [diff] [blame] | 280 | * @brief Get submodule from the context's search dir. |
| 281 | * |
| 282 | * @param[in] module Parent (belongs-to) module. |
| 283 | * @param[in] name Name of the YANG submodule to get. |
| 284 | * @param[in] revision Optional revision date of the YANG submodule to get. If |
| 285 | * not specified, the newest revision is returned (TODO). |
Michal Vasko | 7bf0688 | 2015-07-03 15:33:56 +0200 | [diff] [blame] | 286 | * @return Pointer to the data model structure. |
| 287 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 288 | const struct lys_submodule *ly_ctx_get_submodule(const struct lys_module *module, const char *name, |
| 289 | const char *revision); |
Michal Vasko | 7bf0688 | 2015-07-03 15:33:56 +0200 | [diff] [blame] | 290 | |
| 291 | /** |
Radek Krejci | 704a7a9 | 2015-08-07 12:50:15 +0200 | [diff] [blame] | 292 | * @brief Get schema node according to the given absolute schema node identifier. |
| 293 | * |
Michal Vasko | 8afe75e | 2015-12-11 12:02:20 +0100 | [diff] [blame] | 294 | * Prefix (module name) must be used in two cases. Firstly, the first node MUST |
| 295 | * have a prefix, which is treated as the current module. Secondly, every other |
| 296 | * node MUST have a prefix if its module differs from the current module. |
| 297 | * Here are some examples: |
Radek Krejci | 704a7a9 | 2015-08-07 12:50:15 +0200 | [diff] [blame] | 298 | * |
Michal Vasko | 8afe75e | 2015-12-11 12:02:20 +0100 | [diff] [blame] | 299 | * /ietf-netconf-monitoring:get-schema/input/identifier |
| 300 | * /ietf-interfaces:interfaces/interface/ietf-ip:ipv4/ietf-ip:address/ietf-ip:ip |
| 301 | * |
| 302 | * @param[in] ctx Context to work in. |
| 303 | * @param[in] nodeid Absolute schema node identifier. |
| 304 | * @return Resolved schema node or NULL. |
Radek Krejci | 704a7a9 | 2015-08-07 12:50:15 +0200 | [diff] [blame] | 305 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 306 | const struct lys_node *ly_ctx_get_node(const struct ly_ctx *ctx, const char *nodeid); |
Radek Krejci | 704a7a9 | 2015-08-07 12:50:15 +0200 | [diff] [blame] | 307 | |
| 308 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 309 | * @brief Free all internal structures of the specified context. |
| 310 | * |
| 311 | * The function should be used before terminating the application to destroy |
| 312 | * and free all structures internally used by libyang. If the caller uses |
| 313 | * multiple contexts, the function should be called for each used context. |
| 314 | * |
| 315 | * All instance data are supposed to be freed before destroying the context. |
| 316 | * Data models are destroyed automatically as part of ly_ctx_destroy() call. |
| 317 | * |
| 318 | * @param[in] ctx libyang context to destroy |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 319 | */ |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 320 | void ly_ctx_destroy(struct ly_ctx *ctx); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 321 | |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 322 | /**@} context */ |
| 323 | |
| 324 | /** |
| 325 | * @defgroup parsers Parsers |
| 326 | * @{ |
| 327 | * |
| 328 | * Parsers allows to read schema and data trees from a specific format. |
| 329 | * |
| 330 | * For schemas, the following formats are supported: |
| 331 | * - YANG |
| 332 | * |
| 333 | * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020). |
| 334 | * Currently, only YANG 1.0 is supported. |
| 335 | * |
| 336 | * \todo YANG input is not yet implemented |
| 337 | * |
| 338 | * - YIN |
| 339 | * |
| 340 | * Alternative XML-based format to YANG. The details can be found in |
| 341 | * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11). |
| 342 | * |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 343 | * For data instances, the following formats are supported: |
| 344 | * - \todo TBD |
| 345 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 346 | */ |
| 347 | |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 348 | /** |
Radek Krejci | 704a7a9 | 2015-08-07 12:50:15 +0200 | [diff] [blame] | 349 | * @brief Load a schema into the specified context. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 350 | * |
Radek Krejci | b20c62d | 2015-07-07 17:07:14 +0200 | [diff] [blame] | 351 | * LY_IN_YANG (YANG) format is not yet supported. |
| 352 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 353 | * @param[in] ctx libyang context where to process the data model. |
| 354 | * @param[in] data The string containing the dumped data model in the specified |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 355 | * format. |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 356 | * @param[in] format Format of the input data (YANG or YIN). |
| 357 | * @return Pointer to the data model structure or NULL on error. |
| 358 | */ |
Michal Vasko | 662610a | 2015-12-07 11:25:45 +0100 | [diff] [blame] | 359 | const struct lys_module *lys_parse_data(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 360 | |
Radek Krejci | 704a7a9 | 2015-08-07 12:50:15 +0200 | [diff] [blame] | 361 | /** |
Michal Vasko | 662610a | 2015-12-07 11:25:45 +0100 | [diff] [blame] | 362 | * @brief Load a schema into the specified context from a file. |
| 363 | * |
| 364 | * LY_IN_YANG (YANG) format is not yet supported. |
| 365 | * |
| 366 | * @param[in] ctx libyang context where to process the data model. |
| 367 | * @param[in] path Path to the file with the model in the specified format. |
| 368 | * @param[in] format Format of the input data (YANG or YIN). |
| 369 | * @return Pointer to the data model structure or NULL on error. |
| 370 | */ |
| 371 | const struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format); |
| 372 | |
| 373 | /** |
| 374 | * @brief Read a schema from file descriptor into the specified context. |
Radek Krejci | 704a7a9 | 2015-08-07 12:50:15 +0200 | [diff] [blame] | 375 | * |
| 376 | * LY_IN_YANG (YANG) format is not yet supported. |
| 377 | * |
| 378 | * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc. |
| 379 | * |
| 380 | * @param[in] ctx libyang context where to process the data model. |
Radek Krejci | 4910e24 | 2015-11-30 10:40:45 +0100 | [diff] [blame] | 381 | * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema |
| 382 | * in the specified format. |
Radek Krejci | 704a7a9 | 2015-08-07 12:50:15 +0200 | [diff] [blame] | 383 | * @param[in] format Format of the input data (YANG or YIN). |
| 384 | * @return Pointer to the data model structure or NULL on error. |
| 385 | */ |
Michal Vasko | 662610a | 2015-12-07 11:25:45 +0100 | [diff] [blame] | 386 | const struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 387 | |
| 388 | /** |
Radek Krejci | 25b9fd3 | 2015-08-10 15:06:07 +0200 | [diff] [blame] | 389 | * @defgroup parseroptions Data parser options |
| 390 | * @ingroup parsers |
| 391 | * |
| 392 | * Various options to change the data tree parsers behavior. |
| 393 | * |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 394 | * Default behavior: |
| 395 | * - in case of XML, parser reads all data from its input (file, memory, XML tree) including the case of not well-formed |
| 396 | * XML document (multiple top-level elements) and if there is an unknown element, it is skipped including its subtree |
| 397 | * (see the next point). This can be changed by the #LYD_OPT_NOSIBLINGS option which make parser to read only a single |
| 398 | * tree (with a single root element) from its input. |
| 399 | * - parser silently ignores the data without a matching node in schema trees. If the caller want to stop |
Radek Krejci | 25b9fd3 | 2015-08-10 15:06:07 +0200 | [diff] [blame] | 400 | * parsing in case of presence of unknown data, the #LYD_OPT_STRICT can be used. The strict mode is useful for |
| 401 | * NETCONF servers, since NETCONF clients should always send data according to the capabilities announced by the server. |
| 402 | * On the other hand, the default non-strict mode is useful for clients receiving data from NETCONF server since |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 403 | * clients are not required to understand everything the server does. Of course, the optimal strategy for clients is |
| 404 | * to use filtering to get only the required data. Having an unknown element of the known namespace is always an error. |
| 405 | * The behavior can be changed by #LYD_OPT_STRICT option. |
| 406 | * - using obsolete statements (status set to obsolete) just generates a warning, but the processing continues. The |
| 407 | * behavior can be changed by #LYD_OPT_OBSOLETE option. |
| 408 | * - parser expects that the provided data provides complete datastore content (both the configuration and state data) |
| 409 | * and performs data validation according to all YANG rules. This can be a problem in case of representing NETCONF's |
| 410 | * subtree filter data, edit-config's data or other type of data set - such data do not represent a complete data set |
| 411 | * and some of the validation rules can fail. Therefore there are other options (within lower 8 bits) to make parser |
| 412 | * to accept such a data. |
Radek Krejci | 25b9fd3 | 2015-08-10 15:06:07 +0200 | [diff] [blame] | 413 | * @{ |
| 414 | */ |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 415 | |
| 416 | #define LYD_OPT_DATA 0x00 /**< Default type of data - complete datastore content with configuration as well as |
| 417 | state data. */ |
| 418 | #define LYD_OPT_CONFIG 0x01 /**< A configuration datastore - complete datastore without state data. |
| 419 | Validation modifications: |
| 420 | - status data are not allowed */ |
| 421 | #define LYD_OPT_GET 0x02 /**< Data content from a NETCONF reply message to the NETCONF \<get\> operation. |
| 422 | Validation modifications: |
| 423 | - mandatory nodes can be omitted |
| 424 | - leafrefs and instance-identifier are not resolved |
| 425 | - list's keys/unique nodes are not required (so duplication is not checked) */ |
| 426 | #define LYD_OPT_GETCONFIG 0x04 /**< Data content from a NETCONF reply message to the NETCONF \<get-config\> operation |
| 427 | Validation modifications: |
| 428 | - mandatory nodes can be omitted |
| 429 | - leafrefs and instance-identifier are not resolved |
| 430 | - list's keys/unique nodes are not required (so duplication is not checked) |
| 431 | - status data are not allowed */ |
| 432 | #define LYD_OPT_EDIT 0x08 /**< Content of the NETCONF \<edit-config\>'s config element. |
| 433 | Validation modifications: |
Radek Krejci | 20cdf63 | 2015-11-09 14:44:58 +0100 | [diff] [blame] | 434 | - mandatory nodes can be omitted |
| 435 | - leafrefs and instance-identifier are not resolved |
| 436 | - status data are not allowed */ |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 437 | #define LYD_OPT_RPC 0x10 /**< Data represents RPC's input parameters. */ |
| 438 | #define LYD_OPT_RPCREPLY 0x20 /**< Data represents RPC's output parameters (maps to NETCONF <rpc-reply> data). */ |
| 439 | #define LYD_OPT_NOTIF 0x40 /**< Data represents an event notification data. */ |
| 440 | #define LYD_OPT_FILTER 0x80 /**< Data represents NETCONF subtree filter. Validation modifications: |
Radek Krejci | 20cdf63 | 2015-11-09 14:44:58 +0100 | [diff] [blame] | 441 | - leafs/leaf-lists with no data are allowed (even not allowed e.g. by length restriction) |
| 442 | - multiple instances of container/leaf/.. are allowed |
| 443 | - list's keys/unique nodes are not required |
| 444 | - mandatory nodes can be omitted |
| 445 | - leafrefs and instance-identifier are not resolved |
| 446 | - data from different choice's branches are allowed */ |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 447 | #define LYD_OPT_TYPEMASK 0xff /**< Mask to filter data type options. Always only a single data type option (only |
| 448 | single bit from the lower 8 bits) can be set. */ |
| 449 | |
| 450 | #define LYD_OPT_STRICT 0x0100 /**< Instead of silent ignoring data without schema definition, raise an error. */ |
| 451 | #define LYD_OPT_DESTRUCT 0x0200 /**< Free the provided XML tree during parsing the data. With this option, the |
| 452 | provided XML tree is affected and all succesfully parsed data are freed. |
| 453 | This option is applicable only to lyd_parse_xml() function. */ |
| 454 | #define LYD_OPT_OBSOLETE 0x0400 /**< Raise an error when an obsolete statement (status set to obsolete) is used. */ |
| 455 | #define LYD_OPT_NOSIBLINGS 0x0800 /**< Parse only a single XML tree from the input. This option applies only to |
| 456 | XML input data. */ |
Radek Krejci | 04b97de | 2015-10-31 23:09:15 +0100 | [diff] [blame] | 457 | |
Radek Krejci | 25b9fd3 | 2015-08-10 15:06:07 +0200 | [diff] [blame] | 458 | /** |
| 459 | * @} |
| 460 | */ |
| 461 | |
| 462 | /** |
Radek Krejci | b20c62d | 2015-07-07 17:07:14 +0200 | [diff] [blame] | 463 | * @brief Parse (and validate according to appropriate schema from the given context) data. |
| 464 | * |
Radek Krejci | 8653821 | 2015-12-17 15:59:01 +0100 | [diff] [blame] | 465 | * In case of LY_XML format, the data string is parsed completely. It means that when it contains |
| 466 | * a non well-formed XML with multiple root elements, all those sibling XML trees are parsed. The |
| 467 | * returned data node is a root of the first tree with other trees connected via the next pointer. |
| 468 | * This behavior can be changed by #LYD_OPT_NOSIBLINGS option. |
Radek Krejci | b20c62d | 2015-07-07 17:07:14 +0200 | [diff] [blame] | 469 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 470 | * @param[in] ctx Context to connect with the data tree being built here. |
| 471 | * @param[in] data Serialized data in the specified format. |
| 472 | * @param[in] format Format of the input data to be parsed. |
Radek Krejci | 25b9fd3 | 2015-08-10 15:06:07 +0200 | [diff] [blame] | 473 | * @param[in] options Parser options, see @ref parseroptions. |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 474 | * @param[in] ... Additional argument must be supplied when #LYD_OPT_RPCREPLY value is specified in \p options. The |
| 475 | * argument is supposed to provide pointer to the RPC schema node for the reply's request |
| 476 | * (const struct ::lys_node* rpc). |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 477 | * @return Pointer to the built data tree. To free the returned structure, use lyd_free(). |
Radek Krejci | b20c62d | 2015-07-07 17:07:14 +0200 | [diff] [blame] | 478 | */ |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 479 | struct lyd_node *lyd_parse_data(struct ly_ctx *ctx, const char *data, LYD_FORMAT format, int options, ...); |
Michal Vasko | 36ef693 | 2015-12-01 14:30:17 +0100 | [diff] [blame] | 480 | |
| 481 | /** |
Radek Krejci | c6704c8 | 2015-10-06 11:12:45 +0200 | [diff] [blame] | 482 | * @brief Parse (and validate according to appropriate schema from the given context) XML tree. |
| 483 | * |
| 484 | * The output data tree is parsed from the given XML tree previously parsed by one of the |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 485 | * lyxml_read* functions. |
Radek Krejci | 8653821 | 2015-12-17 15:59:01 +0100 | [diff] [blame] | 486 | * |
| 487 | * If there are some sibling elements of the \p root (data were read with #LYXML_READ_MULTIROOT option |
| 488 | * or the provided root is a root element of a subtree), all the sibling nodes (previous as well as |
| 489 | * following) are processed as well. The returned data node is a root of the first tree with other |
| 490 | * trees connected via the next pointer. This behavior can be changed by #LYD_OPT_NOSIBLINGS option. |
| 491 | * |
| 492 | * When the function is used with #LYD_OPT_DESTRUCT, all the successfully parsed data including the |
| 493 | * XML \p root and all its siblings (if #LYD_OPT_NOSIBLINGS is not used) are freed. Only with |
| 494 | * #LYD_OPT_DESTRUCT option the \p root pointer is changed - if all the data are parsed, it is set |
| 495 | * to NULL, otherwise it will hold the XML tree without the successfully parsed elements. |
Radek Krejci | c6704c8 | 2015-10-06 11:12:45 +0200 | [diff] [blame] | 496 | * |
| 497 | * The context must be the same as the context used to parse XML tree by lyxml_read* function. |
| 498 | * |
| 499 | * @param[in] ctx Context to connect with the data tree being built here. |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 500 | * @param[in,out] root XML tree to parse (convert) to data tree. By default, parser do not change the XML tree. However, |
| 501 | * when #LYD_OPT_DESTRUCT is specified in \p options, parser frees all successfully parsed data. |
Radek Krejci | c6704c8 | 2015-10-06 11:12:45 +0200 | [diff] [blame] | 502 | * @param[in] options Parser options, see @ref parseroptions. |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 503 | * @param[in] ... Additional argument must be supplied when #LYD_OPT_RPCREPLY value is specified in \p options. The |
| 504 | * argument is supposed to provide pointer to the RPC schema node for the reply's request |
| 505 | * (const struct ::lys_node* rpc). |
Radek Krejci | c6704c8 | 2015-10-06 11:12:45 +0200 | [diff] [blame] | 506 | * @return Pointer to the built data tree. To free the returned structure, use lyd_free(). |
| 507 | */ |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 508 | struct lyd_node *lyd_parse_xml(struct ly_ctx *ctx, struct lyxml_elem **root, int options,...); |
Michal Vasko | 36ef693 | 2015-12-01 14:30:17 +0100 | [diff] [blame] | 509 | |
| 510 | /** |
Michal Vasko | 662610a | 2015-12-07 11:25:45 +0100 | [diff] [blame] | 511 | * @brief Read data from the given file descriptor. |
Radek Krejci | 704a7a9 | 2015-08-07 12:50:15 +0200 | [diff] [blame] | 512 | * |
Michal Vasko | 662610a | 2015-12-07 11:25:45 +0100 | [diff] [blame] | 513 | * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc. |
Radek Krejci | 704a7a9 | 2015-08-07 12:50:15 +0200 | [diff] [blame] | 514 | * |
Radek Krejci | 8653821 | 2015-12-17 15:59:01 +0100 | [diff] [blame] | 515 | * In case of LY_XML format, the file content is parsed completely. It means that when it contains |
| 516 | * a non well-formed XML with multiple root elements, all those sibling XML trees are parsed. The |
| 517 | * returned data node is a root of the first tree with other trees connected via the next pointer. |
| 518 | * This behavior can be changed by #LYD_OPT_NOSIBLINGS option. |
| 519 | * |
Radek Krejci | 704a7a9 | 2015-08-07 12:50:15 +0200 | [diff] [blame] | 520 | * @param[in] ctx Context to connect with the data tree being built here. |
| 521 | * @param[in] fd The standard file descriptor of the file containing the data tree in the specified format. |
| 522 | * @param[in] format Format of the input data to be parsed. |
Radek Krejci | 25b9fd3 | 2015-08-10 15:06:07 +0200 | [diff] [blame] | 523 | * @param[in] options Parser options, see @ref parseroptions. |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 524 | * @param[in] ... Additional argument must be supplied when #LYD_OPT_RPCREPLY value is specified in \p options. The |
| 525 | * argument is supposed to provide pointer to the RPC schema node for the reply's request |
| 526 | * (const struct ::lys_node* rpc). |
Radek Krejci | 704a7a9 | 2015-08-07 12:50:15 +0200 | [diff] [blame] | 527 | * @return Pointer to the built data tree. To free the returned structure, use lyd_free(). |
| 528 | */ |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 529 | struct lyd_node *lyd_parse_fd(struct ly_ctx *ctx, int fd, LYD_FORMAT format, int options, ...); |
Michal Vasko | 662610a | 2015-12-07 11:25:45 +0100 | [diff] [blame] | 530 | |
| 531 | /** |
| 532 | * @brief Read data from the given file path. |
| 533 | * |
Radek Krejci | 8653821 | 2015-12-17 15:59:01 +0100 | [diff] [blame] | 534 | * In case of LY_XML format, the file content is parsed completely. It means that when it contains |
| 535 | * a non well-formed XML with multiple root elements, all those sibling XML trees are parsed. The |
| 536 | * returned data node is a root of the first tree with other trees connected via the next pointer. |
| 537 | * This behavior can be changed by #LYD_OPT_NOSIBLINGS option. |
| 538 | * |
Michal Vasko | 662610a | 2015-12-07 11:25:45 +0100 | [diff] [blame] | 539 | * @param[in] ctx Context to connect with the data tree being built here. |
| 540 | * @param[in] path Path to the file containing the data tree in the specified format. |
| 541 | * @param[in] format Format of the input data to be parsed. |
| 542 | * @param[in] options Parser options, see @ref parseroptions. |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 543 | * @param[in] ... Additional argument must be supplied when #LYD_OPT_RPCREPLY value is specified in \p options. The |
| 544 | * argument is supposed to provide pointer to the RPC schema node for the reply's request |
| 545 | * (const struct ::lys_node* rpc). |
Michal Vasko | 662610a | 2015-12-07 11:25:45 +0100 | [diff] [blame] | 546 | * @return Pointer to the built data tree. To free the returned structure, use lyd_free(). |
| 547 | */ |
Radek Krejci | 4a49bdf | 2016-01-12 17:17:01 +0100 | [diff] [blame] | 548 | struct lyd_node *lyd_parse_path(struct ly_ctx *ctx, const char *path, LYD_FORMAT format, int options, ...); |
Radek Krejci | 704a7a9 | 2015-08-07 12:50:15 +0200 | [diff] [blame] | 549 | |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 550 | /**@} parsers */ |
| 551 | |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 552 | /** |
| 553 | * @defgroup schematree Schema Tree |
| 554 | * @{ |
| 555 | * |
| 556 | * Data structures and functions to manipulate and access schema tree. |
| 557 | * |
| 558 | * @} |
| 559 | */ |
| 560 | |
| 561 | /** |
| 562 | * @defgroup datatree Data Tree |
| 563 | * @{ |
| 564 | * |
| 565 | * Data structures and functions to manipulate and access instance data tree. |
| 566 | * |
| 567 | * @} |
| 568 | */ |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 569 | |
| 570 | /** |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 571 | * @defgroup printers Printers |
| 572 | * @{ |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 573 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 574 | * Printers allows to serialize schema and data trees in a specific format. |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 575 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 576 | * For schemas, the following formats are supported: |
| 577 | * - YANG |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 578 | * |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 579 | * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020). |
| 580 | * Currently, only YANG 1.0 is supported. |
| 581 | * |
| 582 | * - YIN |
| 583 | * |
| 584 | * Alternative XML-based format to YANG. The details can be found in |
| 585 | * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11). |
| 586 | * |
| 587 | * \todo YIN output is not yet implemented |
| 588 | * |
| 589 | * - Tree |
| 590 | * |
| 591 | * Simple tree structure of the module. |
| 592 | * |
| 593 | * - Info |
| 594 | * |
| 595 | * Detailed information about the specific node in the schema tree. |
Michal Vasko | 6d6076e | 2015-08-13 15:53:09 +0200 | [diff] [blame] | 596 | * The target can be more specific than the module itself: |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 597 | * |
Michal Vasko | 6d6076e | 2015-08-13 15:53:09 +0200 | [diff] [blame] | 598 | * - absolute-schema-nodeid \a /modules/module-set-id in \a ietf-yang-library |
| 599 | * - <b>typedef/</b>typedef-name \a typedef/revision-identifier in \a ietf-yang-library |
| 600 | * - <b>feature/</b>feature-name \a feature/ssh in \a ietf-netconf-server |
| 601 | * - <b>grouping/</b>grouping-name/descendant-schema-nodeid \a grouping/module or \a grouping/module/module/submodules |
| 602 | * in \a ietf-yang-library |
| 603 | * - <b>type/</b>leaf-or-leaflist \a type/modules/module-set-id in \a ietf-yang-library |
Radek Krejci | d9ba3e3 | 2015-07-30 15:08:18 +0200 | [diff] [blame] | 604 | * |
| 605 | * For data instances, the following formats are supported: |
| 606 | * - \todo TBD |
| 607 | * |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 608 | */ |
| 609 | |
| 610 | /** |
Radek Krejci | 912da45 | 2015-07-29 14:10:06 +0200 | [diff] [blame] | 611 | * @brief Print schema tree in the specified format. |
| 612 | * |
Radek Krejci | 87f5237 | 2015-10-09 09:34:46 +0200 | [diff] [blame] | 613 | * To write data into a file descriptor, use lys_print_fd(). |
| 614 | * |
Radek Krejci | 912da45 | 2015-07-29 14:10:06 +0200 | [diff] [blame] | 615 | * @param[in] module Schema tree to print. |
| 616 | * @param[in] f File stream where to print the schema. |
| 617 | * @param[in] format Schema output format. |
Radek Krejci | a9167ef | 2015-08-03 11:01:11 +0200 | [diff] [blame] | 618 | * @param[in] target_node Optional parameter for ::LYS_OUT_INFO format. It specifies which particular |
Radek Krejci | 912da45 | 2015-07-29 14:10:06 +0200 | [diff] [blame] | 619 | * node in the module will be printed. |
| 620 | * @return 0 on success, 1 on failure (#ly_errno is set). |
| 621 | */ |
Michal Vasko | 662610a | 2015-12-07 11:25:45 +0100 | [diff] [blame] | 622 | int lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node); |
Radek Krejci | 912da45 | 2015-07-29 14:10:06 +0200 | [diff] [blame] | 623 | |
| 624 | /** |
Radek Krejci | 87f5237 | 2015-10-09 09:34:46 +0200 | [diff] [blame] | 625 | * @brief Print schema tree in the specified format. |
| 626 | * |
| 627 | * Same as lys_print(), but output is written into the specified file descriptor. |
| 628 | * |
| 629 | * @param[in] module Schema tree to print. |
| 630 | * @param[in] fd File descriptor where to print the data. |
| 631 | * @param[in] format Schema output format. |
| 632 | * @param[in] target_node Optional parameter for ::LYS_OUT_INFO format. It specifies which particular |
| 633 | * node in the module will be printed. |
| 634 | * @return 0 on success, 1 on failure (#ly_errno is set). |
| 635 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 636 | int lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node); |
Radek Krejci | 87f5237 | 2015-10-09 09:34:46 +0200 | [diff] [blame] | 637 | |
| 638 | /** |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 639 | * @brief Print schema tree in the specified format. |
| 640 | * |
Radek Krejci | 2fa0fc1 | 2015-10-14 18:14:29 +0200 | [diff] [blame] | 641 | * Same as lys_print(), but it allocates memory and store the data into it. |
| 642 | * It is up to caller to free the returned string by free(). |
| 643 | * |
| 644 | * @param[out] strp Pointer to store the resulting dump. |
| 645 | * @param[in] module Schema tree to print. |
| 646 | * @param[in] format Schema output format. |
| 647 | * @param[in] target_node Optional parameter for ::LYS_OUT_INFO format. It specifies which particular |
| 648 | * node in the module will be printed. |
| 649 | * @return 0 on success, 1 on failure (#ly_errno is set). |
| 650 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 651 | int lys_print_mem(char **strp, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node); |
Radek Krejci | 2fa0fc1 | 2015-10-14 18:14:29 +0200 | [diff] [blame] | 652 | |
| 653 | /** |
| 654 | * @brief Print schema tree in the specified format. |
| 655 | * |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 656 | * Same as lys_print(), but output is written via provided callback. |
| 657 | * |
| 658 | * @param[in] module Schema tree to print. |
| 659 | * @param[in] writeclb Callback function to write the data (see write(1)). |
Radek Krejci | 50929eb | 2015-10-09 18:14:15 +0200 | [diff] [blame] | 660 | * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback. |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 661 | * @param[in] format Schema output format. |
| 662 | * @param[in] target_node Optional parameter for ::LYS_OUT_INFO format. It specifies which particular |
| 663 | * node in the module will be printed. |
| 664 | * @return 0 on success, 1 on failure (#ly_errno is set). |
| 665 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 666 | int lys_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, |
| 667 | const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node); |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 668 | |
| 669 | /** |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame^] | 670 | * @defgroup printerflags Printer flags |
| 671 | * @ingroup printers |
| 672 | * |
| 673 | * Validity flags for data nodes. |
| 674 | * |
| 675 | * @{ |
| 676 | */ |
| 677 | #define LYP_WITHSIBLINGS 0x01 /**< Flag for printing also the (following) sibling nodes of the data node. */ |
| 678 | |
| 679 | /** |
| 680 | * @} |
| 681 | */ |
| 682 | |
| 683 | /** |
Radek Krejci | 912da45 | 2015-07-29 14:10:06 +0200 | [diff] [blame] | 684 | * @brief Print data tree in the specified format. |
| 685 | * |
Radek Krejci | 87f5237 | 2015-10-09 09:34:46 +0200 | [diff] [blame] | 686 | * To write data into a file descriptor, use lyd_print_fd(). |
| 687 | * |
Radek Krejci | 912da45 | 2015-07-29 14:10:06 +0200 | [diff] [blame] | 688 | * @param[in] root Root node of the data tree to print. It can be actually any (not only real root) |
| 689 | * node of the data tree to print the specific subtree. |
| 690 | * @param[in] f File stream where to print the data. |
| 691 | * @param[in] format Data output format. |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame^] | 692 | * @param[in] options [printer flags](@ref printerflags). |
Radek Krejci | 912da45 | 2015-07-29 14:10:06 +0200 | [diff] [blame] | 693 | * @return 0 on success, 1 on failure (#ly_errno is set). |
| 694 | */ |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame^] | 695 | int lyd_print_file(FILE *f, const struct lyd_node *root, LYD_FORMAT format, int options); |
Radek Krejci | 912da45 | 2015-07-29 14:10:06 +0200 | [diff] [blame] | 696 | |
Radek Krejci | 87f5237 | 2015-10-09 09:34:46 +0200 | [diff] [blame] | 697 | /** |
| 698 | * @brief Print data tree in the specified format. |
| 699 | * |
| 700 | * Same as lyd_print(), but output is written into the specified file descriptor. |
| 701 | * |
| 702 | * @param[in] root Root node of the data tree to print. It can be actually any (not only real root) |
| 703 | * node of the data tree to print the specific subtree. |
| 704 | * @param[in] fd File descriptor where to print the data. |
| 705 | * @param[in] format Data output format. |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame^] | 706 | * @param[in] options [printer flags](@ref printerflags). |
Radek Krejci | 87f5237 | 2015-10-09 09:34:46 +0200 | [diff] [blame] | 707 | * @return 0 on success, 1 on failure (#ly_errno is set). |
| 708 | */ |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame^] | 709 | int lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, int options); |
Radek Krejci | 87f5237 | 2015-10-09 09:34:46 +0200 | [diff] [blame] | 710 | |
Radek Krejci | 2fa0fc1 | 2015-10-14 18:14:29 +0200 | [diff] [blame] | 711 | |
| 712 | /** |
| 713 | * @brief Print data tree in the specified format. |
| 714 | * |
| 715 | * Same as lyd_print(), but it allocates memory and store the data into it. |
| 716 | * It is up to caller to free the returned string by free(). |
| 717 | * |
| 718 | * @param[out] strp Pointer to store the resulting dump. |
| 719 | * @param[in] root Root node of the data tree to print. It can be actually any (not only real root) |
| 720 | * node of the data tree to print the specific subtree. |
| 721 | * @param[in] format Data output format. |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame^] | 722 | * @param[in] options [printer flags](@ref printerflags). |
Radek Krejci | 2fa0fc1 | 2015-10-14 18:14:29 +0200 | [diff] [blame] | 723 | * @return 0 on success, 1 on failure (#ly_errno is set). |
| 724 | */ |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame^] | 725 | int lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, int options); |
Radek Krejci | 2fa0fc1 | 2015-10-14 18:14:29 +0200 | [diff] [blame] | 726 | |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 727 | /** |
| 728 | * @brief Print data tree in the specified format. |
| 729 | * |
| 730 | * Same as lyd_print(), but output is written via provided callback. |
| 731 | * |
| 732 | * @param[in] root Root node of the data tree to print. It can be actually any (not only real root) |
| 733 | * node of the data tree to print the specific subtree. |
| 734 | * @param[in] writeclb Callback function to write the data (see write(1)). |
Radek Krejci | 50929eb | 2015-10-09 18:14:15 +0200 | [diff] [blame] | 735 | * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback. |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 736 | * @param[in] format Data output format. |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame^] | 737 | * @param[in] options [printer flags](@ref printerflags). |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 738 | * @return 0 on success, 1 on failure (#ly_errno is set). |
| 739 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 740 | int lyd_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame^] | 741 | const struct lyd_node *root, LYD_FORMAT format, int options); |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 742 | |
Radek Krejci | 912da45 | 2015-07-29 14:10:06 +0200 | [diff] [blame] | 743 | /**@} printers */ |
| 744 | |
| 745 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 746 | * @defgroup logger Logger |
| 747 | * @{ |
| 748 | * |
| 749 | * Publicly visible functions and values of the libyang logger. For more |
| 750 | * information, see \ref howtologger. |
| 751 | */ |
| 752 | |
| 753 | /** |
| 754 | * @typedef LY_LOG_LEVEL |
| 755 | * @brief Verbosity levels of the libyang logger. |
| 756 | */ |
| 757 | typedef enum { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 758 | LY_LLERR, /**< Print only error messages. */ |
| 759 | LY_LLWRN, /**< Print error and warning messages. */ |
| 760 | LY_LLVRB, /**< Besides errors and warnings, print some other verbose messages. */ |
| 761 | LY_LLDBG /**< Print all messages including some development debug messages. */ |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 762 | } LY_LOG_LEVEL; |
| 763 | |
| 764 | /** |
| 765 | * @brief Set logger verbosity level. |
| 766 | * @param[in] level Verbosity level. |
| 767 | */ |
| 768 | void ly_verb(LY_LOG_LEVEL level); |
| 769 | |
| 770 | /** |
Michal Vasko | f1d62cf | 2015-12-07 13:17:11 +0100 | [diff] [blame] | 771 | * @brief Set logger callback. |
| 772 | * @param[in] clb Logging callback. |
| 773 | */ |
| 774 | void ly_set_log_clb(void (*clb)(LY_LOG_LEVEL, const char *)); |
| 775 | |
| 776 | /** |
| 777 | * @brief Get logger callback. |
| 778 | * @return Logger callback (can be NULL). |
| 779 | */ |
| 780 | void (*ly_get_log_clb(void))(LY_LOG_LEVEL, const char *); |
| 781 | |
| 782 | /** |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 783 | * @typedef LY_ERR |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 784 | * @brief libyang's error codes available via ly_errno extern variable. |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 785 | * @ingroup logger |
| 786 | */ |
| 787 | typedef enum { |
Radek Krejci | ae6817a | 2015-08-10 14:02:06 +0200 | [diff] [blame] | 788 | 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] | 789 | LY_EMEM, /**< Memory allocation failure */ |
| 790 | LY_ESYS, /**< System call failure */ |
| 791 | LY_EINVAL, /**< Invalid value */ |
| 792 | LY_EINT, /**< Internal error */ |
| 793 | LY_EVALID /**< Validation failure */ |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 794 | } LY_ERR; |
Radek Krejci | 26715a4 | 2015-07-29 14:10:45 +0200 | [diff] [blame] | 795 | /** |
| 796 | * @brief libyang specific errno. |
| 797 | */ |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 798 | extern LY_ERR ly_errno; |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 799 | |
Radek Krejci | 3045cf3 | 2015-05-28 10:58:52 +0200 | [diff] [blame] | 800 | /**@} logger */ |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 801 | |
Radek Krejci | 39d8d0d | 2015-08-17 13:42:45 +0200 | [diff] [blame] | 802 | #ifdef __cplusplus |
| 803 | } |
| 804 | #endif |
| 805 | |
Radek Krejci | 9b4ca39 | 2015-04-10 08:31:27 +0200 | [diff] [blame] | 806 | #endif /* LY_LIBYANG_H_ */ |