blob: 0e34c4c9036eaa341a37c2899f59601205bd8b5c [file] [log] [blame]
Radek Krejci9b4ca392015-04-10 08:31:27 +02001/**
Radek Krejci3045cf32015-05-28 10:58:52 +02002 * @file libyang.h
Radek Krejci9b4ca392015-04-10 08:31:27 +02003 * @author Radek Krejci <rkrejci@cesnet.cz>
Radek Krejci3045cf32015-05-28 10:58:52 +02004 * @brief The main libyang public header.
Radek Krejci9b4ca392015-04-10 08:31:27 +02005 *
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 Krejcida04f4a2015-05-21 12:54:09 +020025#include <stdio.h>
26
Michal Vasko2d162e12015-09-24 14:33:29 +020027#include "tree_schema.h"
28#include "tree_data.h"
Radek Krejcic6704c82015-10-06 11:12:45 +020029#include "xml.h"
Radek Krejcida04f4a2015-05-21 12:54:09 +020030
Radek Krejci39d8d0d2015-08-17 13:42:45 +020031#ifdef __cplusplus
32extern "C" {
33#endif
34
Radek Krejci26715a42015-07-29 14:10:45 +020035/**
36 * @page howto How To ...
37 *
38 * - @subpage howtocontext
Radek Krejcid9ba3e32015-07-30 15:08:18 +020039 * - @subpage howtoschemas
40 * - @subpage howtodata
Radek Krejci26715a42015-07-29 14:10:45 +020041 * - @subpage howtologger
42 */
Radek Krejcida04f4a2015-05-21 12:54:09 +020043
Radek Krejci26715a42015-07-29 14:10:45 +020044/** @page howtocontext Context
45 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +020046 * The context concept allows callers to work in environments with different sets of YANG schemas.
Radek Krejci26715a42015-07-29 14:10:45 +020047 *
48 * The first step in libyang is to create a new context using ly_ctx_new(). It returns a handler
49 * used in the following work.
50 *
51 * When creating a new context, search dir can be specified (NULL is accepted) to provide directory
52 * where libyang will automatically search for schemas being imported or included. The search path
53 * can be later changed via ly_ctx_set_searchdir() function. Before exploring the specified search
54 * dir, libyang tries to get imported and included schemas from the current working directory first.
55 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +020056 * Schemas are added into the context using [parser functions](@ref parsers) - lys_parse() or lys_read().
57 * Note, that parser functions for schemas have \b lys_ prefix while instance data parser functions have
58 * \b lyd_ prefix.
59 *
Radek Krejcif647e612015-07-30 11:36:07 +020060 * Context can hold multiple revisons of the same schema.
Radek Krejci26715a42015-07-29 14:10:45 +020061 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +020062 * Context holds all modules and their submodules internally. The list of available module names is
63 * provided via ly_ctx_get_module_names() functions. Similarly, caller can get also a list of submodules
64 * names of a specific module using ly_ctx_get_submodule_names() function. The returned names can be
65 * subsequently used to get the (sub)module structures using ly_ctx_get_module() and ly_ctx_get_submodule().
66 *
67 * Modules held by a context cannot be removed one after one. The only way how to \em change modules in the
68 * context is to create a new context and remove the old one. To remove a context, there is ly_ctx_destroy()
69 * function.
70 *
71 * \note API for this group of functions is available in the [context module](@ref context).
72 *
73 */
74
75/**
76 * @page howtoschemas Schemas
77 *
78 * Schema is an internal libyang's representation of a YANG data model. Each schema is connected with
79 * its [context](@ref howtocontext) and loaded using [parser functions](@ref parsers). It means, that
80 * the schema cannot be created (nor changed) programatically. In libyang, schemas are used only to
81 * access data model definitions.
82 *
83 * \note There are many functions to access information from the schema trees. Details are available in
84 * the [Schema Tree module](@ref schematree).
85 *
86 * YANG Features Manipulation
87 * --------------------------
88 *
89 * The group of functions prefixed by \b lys_features_ are used to access and manipulate with the schema's
90 * features.
91 *
92 * The first two functions are used to access information about the features in the schema.
93 * lys_features_list() provides list of all features defined in the specific schema and its
94 * submodules. Optionally, it can also provides information about the state of all features.
95 * Alternatively, caller can use lys_features_state() function to get state of one specific
96 * feature.
97 *
98 * The remaining two functions, lys_features_enable() and lys_features_disable(), are used
99 * to enable and disable the specific feature. By default, when the module is loaded by libyang
100 * parser, all features are disabled.
101 *
102 * Note, that feature's state can affect some of the output formats (e.g. Tree format).
103 *
104 */
105
106/**
107 * @page howtodata Data Instances
Radek Krejci26715a42015-07-29 14:10:45 +0200108 *
109 */
Radek Krejci94ca54b2015-07-08 15:48:47 +0200110
Radek Krejcida04f4a2015-05-21 12:54:09 +0200111/**
Radek Krejci26715a42015-07-29 14:10:45 +0200112 *
113 * @page howtologger Logger
114 *
115 * There are 4 verbosity levels defined as ::LY_LOG_LEVEL. The level can be
116 * changed by the ly_verb() function. By default, the verbosity level is
117 * set to #LY_LLERR value.
118 *
119 * In case the logger has an error message (LY_LLERR) to print, also an error
120 * code is recorded in extern ly_errno variable. Possible values are of type
121 * ::LY_ERR.
122 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200123 * \note API for this group of functions is available in the [logger module](@ref logger).
Radek Krejci26715a42015-07-29 14:10:45 +0200124 */
125
126/**
127 * @defgroup context Context
Radek Krejci3045cf32015-05-28 10:58:52 +0200128 * @{
129 *
Radek Krejci26715a42015-07-29 14:10:45 +0200130 * Structures and functions to manipulate with the libyang "containers". The \em context concept allows callers
131 * to work in environments with different sets of YANG schemas. More detailed information can be found at
132 * @ref howtocontext page.
Radek Krejci3045cf32015-05-28 10:58:52 +0200133 */
134
135/**
Radek Krejcida04f4a2015-05-21 12:54:09 +0200136 * @brief libyang context handler.
137 */
138struct ly_ctx;
139
140/**
141 * @brief Create libyang context
142 *
Radek Krejci26715a42015-07-29 14:10:45 +0200143 * Context is used to hold all information about schemas. Usually, the application is supposed
Radek Krejci91b833c2015-09-04 11:49:43 +0200144 * to work with a single context in which libyang is holding all schemas (and other internal
145 * information) according to which the data trees will be processed and validated. So, the schema
146 * trees are tightly connected with the specific context and they are held by the context internally
147 * - caller does not need to keep pointers to the schemas returned by lys_parse(), context knows
148 * about them. The data trees created with lyd_parse() are still connected with the specific context,
149 * but they are not internally held by the context. The data tree just points and lean on some data
150 * held by the context (schema tree, string dictionary, etc.). Therefore, in case of data trees, caller
151 * is supposed to keep pointers returned by the lyd_parse() and manage the data tree on its own. This
152 * also affects the number of instances of both tree types. While you can have only one instance of
153 * specific schema connected with a single context, number of data tree instances is not connected.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200154 *
Radek Krejci26715a42015-07-29 14:10:45 +0200155 * @param[in] search_dir Directory where libyang will search for the imported or included modules
156 * and submodules. If no such directory is available, NULL is accepted.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200157 *
Radek Krejci3045cf32015-05-28 10:58:52 +0200158 * @return Pointer to the created libyang context, NULL in case of error.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200159 */
160struct ly_ctx *ly_ctx_new(const char *search_dir);
161
162/**
Michal Vasko60ba9a62015-07-03 14:42:31 +0200163 * @brief Change the search path in libyang context
164 *
165 * @param[in] ctx Context to be modified.
166 * @param[in] search_dir New search path to replace the current one in ctx.
167 */
168void ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir);
169
170/**
Radek Krejci7ab25152015-08-07 14:48:45 +0200171 * @brief Get data of an internal ietf-yang-library module.
172 *
173 * @param[in] ctx Context with the modules.
174 * @return Root data node corresponding to the model, NULL on error.
175 * Caller is responsible for freeing the returned data tree using lyd_free().
176 */
177struct lyd_node *ly_ctx_info(struct ly_ctx *ctx);
178
179/**
Radek Krejci96a10da2015-07-30 11:00:14 +0200180 * @brief Get the names of the loaded modules.
181 *
182 * @param[in] ctx Context with the modules.
183 * @return NULL-terminated array of the module names,
184 * NULL on error. The returned array must be freed by the caller, do not free
185 * names in the array. Also remember that the names will be freed with freeing
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200186 * the context.
Radek Krejci96a10da2015-07-30 11:00:14 +0200187 */
188const char **ly_ctx_get_module_names(struct ly_ctx *ctx);
189
190/**
191 * @brief Get the names of the loaded submodules of the specified module.
192 *
193 * @param[in] ctx Context with the modules.
194 * @param[in] module_name Name of the parent module.
195 * @return NULL-terminated array of submodule names of the parent module,
196 * NULL on error. The returned array must be freed by the caller, do not free
197 * names in the array. Also remember that the names will be freed with freeing
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200198 * the context.
Radek Krejci96a10da2015-07-30 11:00:14 +0200199 */
200const char **ly_ctx_get_submodule_names(struct ly_ctx *ctx, const char *module_name);
201
202/**
Radek Krejcifd4e6e32015-08-10 15:00:51 +0200203 * @brief Get pointer to the schema tree of the module of the specified name.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200204 *
Radek Krejcida04f4a2015-05-21 12:54:09 +0200205 * @param[in] ctx Context to work in.
206 * @param[in] name Name of the YANG module to get.
Radek Krejcif647e612015-07-30 11:36:07 +0200207 * @param[in] revision Optional revision date of the YANG module to get. If not specified,
208 * the schema in the newest revision is returned if any.
209 * @return Pointer to the data model structure, NULL if no schema following the name and
Radek Krejcifd4e6e32015-08-10 15:00:51 +0200210 * revision requirements is present in the context.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200211 */
Radek Krejcib8048692015-08-05 13:36:34 +0200212struct lys_module *ly_ctx_get_module(struct ly_ctx *ctx, const char *name, const char *revision);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200213
214/**
Radek Krejcifd4e6e32015-08-10 15:00:51 +0200215 * @brief Get pointer to the schema tree of the module of the specified namespace
216 *
217 * @param[in] ctx Context to work in.
218 * @param[in] ns Namespace of the YANG module to get.
219 * @param[in] revision Optional revision date of the YANG module to get. If not specified,
220 * the schema in the newest revision is returned if any.
221 * @return Pointer to the data model structure, NULL if no schema following the namespace and
222 * revision requirements is present in the context.
223 */
224struct lys_module *ly_ctx_get_module_by_ns(struct ly_ctx *ctx, const char *ns, const char *revision);
225
226/**
Michal Vasko7bf06882015-07-03 15:33:56 +0200227 * @brief Get submodule from the context's search dir.
228 *
229 * @param[in] module Parent (belongs-to) module.
230 * @param[in] name Name of the YANG submodule to get.
231 * @param[in] revision Optional revision date of the YANG submodule to get. If
232 * not specified, the newest revision is returned (TODO).
Michal Vasko7bf06882015-07-03 15:33:56 +0200233 * @return Pointer to the data model structure.
234 */
Radek Krejcib8048692015-08-05 13:36:34 +0200235struct lys_submodule *ly_ctx_get_submodule(struct lys_module *module, const char *name, const char *revision);
Michal Vasko7bf06882015-07-03 15:33:56 +0200236
237/**
Radek Krejci704a7a92015-08-07 12:50:15 +0200238 * @brief Get schema node according to the given absolute schema node identifier.
239 *
240 * TODO not implemented
241 *
242 * @param[in] ctx Context to work in.
243 * @param[in] nodeid Absolute schema node identifier with module names used as
244 * prefixes. Prefix (module name) must be used whenever the child node is from
245 * other module (augments the parent node). The first node in the path must be
246 * always specified with the prefix. Here are some examples:
247 *
248 * - /ietf-netconf-monitoring:get-schema/input/identifier
249 * - /ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address/ip
250 */
251struct lys_node *lys_ctx_get_node(struct ly_ctx *ctx, const char *nodeid);
252
253/**
Radek Krejci3045cf32015-05-28 10:58:52 +0200254 * @brief Free all internal structures of the specified context.
255 *
256 * The function should be used before terminating the application to destroy
257 * and free all structures internally used by libyang. If the caller uses
258 * multiple contexts, the function should be called for each used context.
259 *
260 * All instance data are supposed to be freed before destroying the context.
261 * Data models are destroyed automatically as part of ly_ctx_destroy() call.
262 *
263 * @param[in] ctx libyang context to destroy
Radek Krejcida04f4a2015-05-21 12:54:09 +0200264 */
Radek Krejci3045cf32015-05-28 10:58:52 +0200265void ly_ctx_destroy(struct ly_ctx *ctx);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200266
Radek Krejci26715a42015-07-29 14:10:45 +0200267/**@} context */
268
269/**
270 * @defgroup parsers Parsers
271 * @{
272 *
273 * Parsers allows to read schema and data trees from a specific format.
274 *
275 * For schemas, the following formats are supported:
276 * - YANG
277 *
278 * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020).
279 * Currently, only YANG 1.0 is supported.
280 *
281 * \todo YANG input is not yet implemented
282 *
283 * - YIN
284 *
285 * Alternative XML-based format to YANG. The details can be found in
286 * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11).
287 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200288 * For data instances, the following formats are supported:
289 * - \todo TBD
290 *
Radek Krejci26715a42015-07-29 14:10:45 +0200291 */
292
Radek Krejcida04f4a2015-05-21 12:54:09 +0200293/**
Radek Krejci704a7a92015-08-07 12:50:15 +0200294 * @brief Load a schema into the specified context.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200295 *
Radek Krejcib20c62d2015-07-07 17:07:14 +0200296 * LY_IN_YANG (YANG) format is not yet supported.
297 *
Radek Krejcida04f4a2015-05-21 12:54:09 +0200298 * @param[in] ctx libyang context where to process the data model.
299 * @param[in] data The string containing the dumped data model in the specified
Michal Vaskod8aa32d2015-07-24 11:50:01 +0200300 * format.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200301 * @param[in] format Format of the input data (YANG or YIN).
302 * @return Pointer to the data model structure or NULL on error.
303 */
Radek Krejcib8048692015-08-05 13:36:34 +0200304struct lys_module *lys_parse(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200305
Radek Krejci704a7a92015-08-07 12:50:15 +0200306/**
307 * @brief Read a schema from file into the specified context.
308 *
309 * LY_IN_YANG (YANG) format is not yet supported.
310 *
311 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
312 *
313 * @param[in] ctx libyang context where to process the data model.
314 * @param[in] fd The standard file descriptor of the file containing the schema in the specified format.
315 * @param[in] format Format of the input data (YANG or YIN).
316 * @return Pointer to the data model structure or NULL on error.
317 */
Radek Krejcib8048692015-08-05 13:36:34 +0200318struct lys_module *lys_read(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200319
320/**
Radek Krejci25b9fd32015-08-10 15:06:07 +0200321 * @defgroup parseroptions Data parser options
322 * @ingroup parsers
323 *
324 * Various options to change the data tree parsers behavior.
325 *
326 * By default, parser silently ignores the data without a matching node in schema trees. If the caller want to stop
327 * parsing in case of presence of unknown data, the #LYD_OPT_STRICT can be used. The strict mode is useful for
328 * NETCONF servers, since NETCONF clients should always send data according to the capabilities announced by the server.
329 * On the other hand, the default non-strict mode is useful for clients receiving data from NETCONF server since
330 * clients are not required to understand everything the server does. Of course, the optimal strategy is to use
331 * filtering to get only the required data.
332 *
333 * Parser also expects that the provided data are complete and performs data validation according to all
334 * implemented YANG rules. This can be problem in case of representing NETCONF's subtree filter data or
335 * edit-config's data which do not represent a complete data set. Therefore there are two options to make parser to
Michal Vasko163faae2015-10-02 15:23:00 +0200336 * accept such a data: #LYD_OPT_FILTER and #LYD_OPT_EDIT. However, both these options are ignored when parsing
337 * an RPC or a notification.
Radek Krejci25b9fd32015-08-10 15:06:07 +0200338 *
339 * @{
340 */
Michal Vasko163faae2015-10-02 15:23:00 +0200341#define LYD_OPT_STRICT 0x01 /**< instead of silent ignoring data without schema definition, raise an error.
Radek Krejci25b9fd32015-08-10 15:06:07 +0200342 Having an unknown element of the known namespace is always an error. */
Radek Krejcib1c12512015-08-11 11:22:04 +0200343#define LYD_OPT_EDIT 0x02 /**< make validation to accept NETCONF edit-config's content:
344 - mandatory nodes can be omitted
Radek Krejcibc9ee4f2015-08-19 13:44:51 +0200345 - leafrefs and instance-identifier are not resolved
346 - status data are not allowed */
Radek Krejcib1c12512015-08-11 11:22:04 +0200347#define LYD_OPT_FILTER 0x04 /**< make validation to accept NETCONF subtree filter data:
Radek Krejci25b9fd32015-08-10 15:06:07 +0200348 - leafs/leaf-lists with no data are allowed (even not allowed e.g. by length restriction)
349 - multiple instances of container/leaf/.. are allowed
350 - list's keys are not required
Radek Krejcib1c12512015-08-11 11:22:04 +0200351 - mandatory nodes can be omitted
Radek Krejcibc9ee4f2015-08-19 13:44:51 +0200352 - leafrefs and instance-identifier are not resolved
353 - data from different choice's branches are allowed */
Radek Krejci25b9fd32015-08-10 15:06:07 +0200354/**
355 * @}
356 */
357
358/**
Radek Krejcib20c62d2015-07-07 17:07:14 +0200359 * @brief Parse (and validate according to appropriate schema from the given context) data.
360 *
Radek Krejci4f0a8742015-08-12 10:09:28 +0200361 * In case of LY_XML format, the data string is expected to contain XML data under a single
362 * XML element. The element is not parsed, but it is expected to keep XML data well formed in all
363 * cases. There are no restrictions for the element name or its namespace.
Radek Krejcib20c62d2015-07-07 17:07:14 +0200364 *
365 * LY_JSON format is not yet supported.
Radek Krejci26715a42015-07-29 14:10:45 +0200366 *
367 * @param[in] ctx Context to connect with the data tree being built here.
368 * @param[in] data Serialized data in the specified format.
369 * @param[in] format Format of the input data to be parsed.
Radek Krejci25b9fd32015-08-10 15:06:07 +0200370 * @param[in] options Parser options, see @ref parseroptions.
Radek Krejci26715a42015-07-29 14:10:45 +0200371 * @return Pointer to the built data tree. To free the returned structure, use lyd_free().
Radek Krejcib20c62d2015-07-07 17:07:14 +0200372 */
Radek Krejci25b9fd32015-08-10 15:06:07 +0200373struct lyd_node *lyd_parse(struct ly_ctx *ctx, const char *data, LYD_FORMAT format, int options);
Radek Krejcib20c62d2015-07-07 17:07:14 +0200374
Radek Krejci704a7a92015-08-07 12:50:15 +0200375/**
Radek Krejcic6704c82015-10-06 11:12:45 +0200376 * @brief Parse (and validate according to appropriate schema from the given context) XML tree.
377 *
378 * The output data tree is parsed from the given XML tree previously parsed by one of the
379 * lyxml_read* functions. Note, that the parser removes successfully parsed data from the
380 * XML tree except the root element (see the note about XML format in lyd_parse()). When
381 * the given XML tree is successfully parsed, the given \p root is kept but it has no children
382 * which are returned as a top level nodes in the output data tree.
383 *
384 * The context must be the same as the context used to parse XML tree by lyxml_read* function.
385 *
386 * @param[in] ctx Context to connect with the data tree being built here.
387 * @param[in] root XML tree to parse (convert) to data tree.
388 * @param[in] options Parser options, see @ref parseroptions.
389 * @return Pointer to the built data tree. To free the returned structure, use lyd_free().
390 */
391struct lyd_node *lyd_parse_xml(struct ly_ctx *ctx, struct lyxml_elem *root, int options);
392
393/**
Radek Krejci704a7a92015-08-07 12:50:15 +0200394 * @brief Read data from the given file
395 *
396 * TODO not implemented
397 *
398 * @param[in] ctx Context to connect with the data tree being built here.
399 * @param[in] fd The standard file descriptor of the file containing the data tree in the specified format.
400 * @param[in] format Format of the input data to be parsed.
Radek Krejci25b9fd32015-08-10 15:06:07 +0200401 * @param[in] options Parser options, see @ref parseroptions.
Radek Krejci704a7a92015-08-07 12:50:15 +0200402 * @return Pointer to the built data tree. To free the returned structure, use lyd_free().
403 */
Radek Krejci25b9fd32015-08-10 15:06:07 +0200404struct lyd_node *lyd_read(struct ly_ctx *ctx, int fd, LYD_FORMAT format, int options);
Radek Krejci704a7a92015-08-07 12:50:15 +0200405
Radek Krejci26715a42015-07-29 14:10:45 +0200406/**@} parsers */
407
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200408/**
409 * @defgroup schematree Schema Tree
410 * @{
411 *
412 * Data structures and functions to manipulate and access schema tree.
413 *
414 * @}
415 */
416
417/**
418 * @defgroup datatree Data Tree
419 * @{
420 *
421 * Data structures and functions to manipulate and access instance data tree.
422 *
423 * @}
424 */
Radek Krejci9b4ca392015-04-10 08:31:27 +0200425
426/**
Radek Krejci26715a42015-07-29 14:10:45 +0200427 * @defgroup printers Printers
428 * @{
Radek Krejci9b4ca392015-04-10 08:31:27 +0200429 *
Radek Krejci26715a42015-07-29 14:10:45 +0200430 * Printers allows to serialize schema and data trees in a specific format.
Radek Krejci9b4ca392015-04-10 08:31:27 +0200431 *
Radek Krejci26715a42015-07-29 14:10:45 +0200432 * For schemas, the following formats are supported:
433 * - YANG
Radek Krejci9b4ca392015-04-10 08:31:27 +0200434 *
Radek Krejci26715a42015-07-29 14:10:45 +0200435 * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020).
436 * Currently, only YANG 1.0 is supported.
437 *
438 * - YIN
439 *
440 * Alternative XML-based format to YANG. The details can be found in
441 * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11).
442 *
443 * \todo YIN output is not yet implemented
444 *
445 * - Tree
446 *
447 * Simple tree structure of the module.
448 *
449 * - Info
450 *
451 * Detailed information about the specific node in the schema tree.
Michal Vasko6d6076e2015-08-13 15:53:09 +0200452 * The target can be more specific than the module itself:
Radek Krejci26715a42015-07-29 14:10:45 +0200453 *
Michal Vasko6d6076e2015-08-13 15:53:09 +0200454 * - absolute-schema-nodeid&nbsp;&nbsp;&nbsp;&nbsp;\a /modules/module-set-id in \a ietf-yang-library
455 * - <b>typedef/</b>typedef-name&nbsp;&nbsp;&nbsp;&nbsp;\a typedef/revision-identifier in \a ietf-yang-library
456 * - <b>feature/</b>feature-name&nbsp;&nbsp;&nbsp;&nbsp;\a feature/ssh in \a ietf-netconf-server
457 * - <b>grouping/</b>grouping-name/descendant-schema-nodeid&nbsp;&nbsp;&nbsp;&nbsp;\a grouping/module or \a grouping/module/module/submodules
458 * in \a ietf-yang-library
459 * - <b>type/</b>leaf-or-leaflist&nbsp;&nbsp;&nbsp;&nbsp;\a type/modules/module-set-id in \a ietf-yang-library
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200460 *
461 * For data instances, the following formats are supported:
462 * - \todo TBD
463 *
Radek Krejci9b4ca392015-04-10 08:31:27 +0200464 */
465
466/**
Radek Krejci912da452015-07-29 14:10:06 +0200467 * @brief Print schema tree in the specified format.
468 *
Radek Krejci87f52372015-10-09 09:34:46 +0200469 * To write data into a file descriptor, use lys_print_fd().
470 *
Radek Krejci912da452015-07-29 14:10:06 +0200471 * @param[in] module Schema tree to print.
472 * @param[in] f File stream where to print the schema.
473 * @param[in] format Schema output format.
Radek Krejcia9167ef2015-08-03 11:01:11 +0200474 * @param[in] target_node Optional parameter for ::LYS_OUT_INFO format. It specifies which particular
Radek Krejci912da452015-07-29 14:10:06 +0200475 * node in the module will be printed.
476 * @return 0 on success, 1 on failure (#ly_errno is set).
477 */
Radek Krejcib8048692015-08-05 13:36:34 +0200478int lys_print(FILE *f, struct lys_module *module, LYS_OUTFORMAT format, const char *target_node);
Radek Krejci912da452015-07-29 14:10:06 +0200479
480/**
Radek Krejci87f52372015-10-09 09:34:46 +0200481 * @brief Print schema tree in the specified format.
482 *
483 * Same as lys_print(), but output is written into the specified file descriptor.
484 *
485 * @param[in] module Schema tree to print.
486 * @param[in] fd File descriptor where to print the data.
487 * @param[in] format Schema output format.
488 * @param[in] target_node Optional parameter for ::LYS_OUT_INFO format. It specifies which particular
489 * node in the module will be printed.
490 * @return 0 on success, 1 on failure (#ly_errno is set).
491 */
492int lys_print_fd(int fd, struct lys_module *module, LYS_OUTFORMAT format, const char *target_node);
493
494/**
Radek Krejci6140e4e2015-10-09 15:50:55 +0200495 * @brief Print schema tree in the specified format.
496 *
497 * Same as lys_print(), but output is written via provided callback.
498 *
499 * @param[in] module Schema tree to print.
500 * @param[in] writeclb Callback function to write the data (see write(1)).
Radek Krejci50929eb2015-10-09 18:14:15 +0200501 * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
Radek Krejci6140e4e2015-10-09 15:50:55 +0200502 * @param[in] format Schema output format.
503 * @param[in] target_node Optional parameter for ::LYS_OUT_INFO format. It specifies which particular
504 * node in the module will be printed.
505 * @return 0 on success, 1 on failure (#ly_errno is set).
506 */
Radek Krejci50929eb2015-10-09 18:14:15 +0200507int lys_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, struct lys_module *module, LYS_OUTFORMAT format, const char *target_node);
Radek Krejci6140e4e2015-10-09 15:50:55 +0200508
509/**
Radek Krejci912da452015-07-29 14:10:06 +0200510 * @brief Print data tree in the specified format.
511 *
Radek Krejci87f52372015-10-09 09:34:46 +0200512 * To write data into a file descriptor, use lyd_print_fd().
513 *
Radek Krejci912da452015-07-29 14:10:06 +0200514 * @param[in] root Root node of the data tree to print. It can be actually any (not only real root)
515 * node of the data tree to print the specific subtree.
516 * @param[in] f File stream where to print the data.
517 * @param[in] format Data output format.
518 * @return 0 on success, 1 on failure (#ly_errno is set).
519 */
Radek Krejcia9167ef2015-08-03 11:01:11 +0200520int lyd_print(FILE *f, struct lyd_node *root, LYD_FORMAT format);
Radek Krejci912da452015-07-29 14:10:06 +0200521
Radek Krejci87f52372015-10-09 09:34:46 +0200522/**
523 * @brief Print data tree in the specified format.
524 *
525 * Same as lyd_print(), but output is written into the specified file descriptor.
526 *
527 * @param[in] root Root node of the data tree to print. It can be actually any (not only real root)
528 * node of the data tree to print the specific subtree.
529 * @param[in] fd File descriptor where to print the data.
530 * @param[in] format Data output format.
531 * @return 0 on success, 1 on failure (#ly_errno is set).
532 */
533int lyd_print_fd(int fd, struct lyd_node *root, LYD_FORMAT format);
534
Radek Krejci6140e4e2015-10-09 15:50:55 +0200535/**
536 * @brief Print data tree in the specified format.
537 *
538 * Same as lyd_print(), but output is written via provided callback.
539 *
540 * @param[in] root Root node of the data tree to print. It can be actually any (not only real root)
541 * node of the data tree to print the specific subtree.
542 * @param[in] writeclb Callback function to write the data (see write(1)).
Radek Krejci50929eb2015-10-09 18:14:15 +0200543 * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
Radek Krejci6140e4e2015-10-09 15:50:55 +0200544 * @param[in] format Data output format.
545 * @return 0 on success, 1 on failure (#ly_errno is set).
546 */
Radek Krejci50929eb2015-10-09 18:14:15 +0200547int lyd_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, struct lyd_node *root, LYD_FORMAT format);
Radek Krejci6140e4e2015-10-09 15:50:55 +0200548
Radek Krejci912da452015-07-29 14:10:06 +0200549/**@} printers */
550
551/**
Radek Krejci3045cf32015-05-28 10:58:52 +0200552 * @defgroup logger Logger
553 * @{
554 *
555 * Publicly visible functions and values of the libyang logger. For more
556 * information, see \ref howtologger.
557 */
558
559/**
560 * @typedef LY_LOG_LEVEL
561 * @brief Verbosity levels of the libyang logger.
562 */
563typedef enum {
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200564 LY_LLERR, /**< Print only error messages. */
565 LY_LLWRN, /**< Print error and warning messages. */
566 LY_LLVRB, /**< Besides errors and warnings, print some other verbose messages. */
567 LY_LLDBG /**< Print all messages including some development debug messages. */
Radek Krejci3045cf32015-05-28 10:58:52 +0200568} LY_LOG_LEVEL;
569
570/**
571 * @brief Set logger verbosity level.
572 * @param[in] level Verbosity level.
573 */
574void ly_verb(LY_LOG_LEVEL level);
575
576/**
577 * @typedef LY_ERR
Radek Krejci26715a42015-07-29 14:10:45 +0200578 * @brief libyang's error codes available via ly_errno extern variable.
Radek Krejci9b4ca392015-04-10 08:31:27 +0200579 * @ingroup logger
580 */
581typedef enum {
Radek Krejciae6817a2015-08-10 14:02:06 +0200582 LY_SUCCESS, /**< no error, not set by functions, included just to complete #LY_ERR enumeration */
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200583 LY_EMEM, /**< Memory allocation failure */
584 LY_ESYS, /**< System call failure */
585 LY_EINVAL, /**< Invalid value */
586 LY_EINT, /**< Internal error */
587 LY_EVALID /**< Validation failure */
Radek Krejci3045cf32015-05-28 10:58:52 +0200588} LY_ERR;
Radek Krejci26715a42015-07-29 14:10:45 +0200589/**
590 * @brief libyang specific errno.
591 */
Radek Krejci3045cf32015-05-28 10:58:52 +0200592extern LY_ERR ly_errno;
Radek Krejci9b4ca392015-04-10 08:31:27 +0200593
Radek Krejci3045cf32015-05-28 10:58:52 +0200594/**@} logger */
Radek Krejci9b4ca392015-04-10 08:31:27 +0200595
Radek Krejci39d8d0d2015-08-17 13:42:45 +0200596#ifdef __cplusplus
597}
598#endif
599
Radek Krejci9b4ca392015-04-10 08:31:27 +0200600#endif /* LY_LIBYANG_H_ */