blob: 5ccfcf761d26ca815df7c1aa8d217885b7767eca [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 Krejci41912fe2015-10-22 10:22:12 +020030#include "dict.h"
Radek Krejcida04f4a2015-05-21 12:54:09 +020031
Radek Krejci39d8d0d2015-08-17 13:42:45 +020032#ifdef __cplusplus
33extern "C" {
34#endif
35
Radek Krejci26715a42015-07-29 14:10:45 +020036/**
37 * @page howto How To ...
38 *
39 * - @subpage howtocontext
Radek Krejcid9ba3e32015-07-30 15:08:18 +020040 * - @subpage howtoschemas
41 * - @subpage howtodata
Radek Krejci26715a42015-07-29 14:10:45 +020042 * - @subpage howtologger
43 */
Radek Krejcida04f4a2015-05-21 12:54:09 +020044
Radek Krejci26715a42015-07-29 14:10:45 +020045/** @page howtocontext Context
46 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +020047 * The context concept allows callers to work in environments with different sets of YANG schemas.
Radek Krejci26715a42015-07-29 14:10:45 +020048 *
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 Krejcid9ba3e32015-07-30 15:08:18 +020057 * 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 Krejcif647e612015-07-30 11:36:07 +020061 * Context can hold multiple revisons of the same schema.
Radek Krejci26715a42015-07-29 14:10:45 +020062 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +020063 * 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 Krejci26715a42015-07-29 14:10:45 +0200109 *
110 */
Radek Krejci94ca54b2015-07-08 15:48:47 +0200111
Radek Krejcida04f4a2015-05-21 12:54:09 +0200112/**
Radek Krejci26715a42015-07-29 14:10:45 +0200113 *
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 Krejcid9ba3e32015-07-30 15:08:18 +0200124 * \note API for this group of functions is available in the [logger module](@ref logger).
Radek Krejci26715a42015-07-29 14:10:45 +0200125 */
126
127/**
128 * @defgroup context Context
Radek Krejci3045cf32015-05-28 10:58:52 +0200129 * @{
130 *
Radek Krejci26715a42015-07-29 14:10:45 +0200131 * 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 Krejci3045cf32015-05-28 10:58:52 +0200134 */
135
136/**
Radek Krejcida04f4a2015-05-21 12:54:09 +0200137 * @brief libyang context handler.
138 */
139struct ly_ctx;
140
141/**
142 * @brief Create libyang context
143 *
Radek Krejci26715a42015-07-29 14:10:45 +0200144 * Context is used to hold all information about schemas. Usually, the application is supposed
Radek Krejci91b833c2015-09-04 11:49:43 +0200145 * 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 Krejcida04f4a2015-05-21 12:54:09 +0200155 *
Radek Krejci26715a42015-07-29 14:10:45 +0200156 * @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 Krejcida04f4a2015-05-21 12:54:09 +0200158 *
Radek Krejci3045cf32015-05-28 10:58:52 +0200159 * @return Pointer to the created libyang context, NULL in case of error.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200160 */
161struct ly_ctx *ly_ctx_new(const char *search_dir);
162
163/**
Michal Vasko60ba9a62015-07-03 14:42:31 +0200164 * @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 */
169void ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir);
170
171/**
Radek Krejci5a797572015-10-21 15:45:45 +0200172 * @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 Vasko1e62a092015-12-01 12:27:20 +0100177const char *ly_ctx_get_searchdir(const struct ly_ctx *ctx);
Radek Krejci5a797572015-10-21 15:45:45 +0200178
179/**
Radek Krejci7ab25152015-08-07 14:48:45 +0200180 * @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 */
186struct lyd_node *ly_ctx_info(struct ly_ctx *ctx);
187
188/**
Radek Krejci96a10da2015-07-30 11:00:14 +0200189 * @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 Krejcid9ba3e32015-07-30 15:08:18 +0200195 * the context.
Radek Krejci96a10da2015-07-30 11:00:14 +0200196 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100197const char **ly_ctx_get_module_names(const struct ly_ctx *ctx);
Radek Krejci96a10da2015-07-30 11:00:14 +0200198
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 Krejcid9ba3e32015-07-30 15:08:18 +0200207 * the context.
Radek Krejci96a10da2015-07-30 11:00:14 +0200208 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100209const char **ly_ctx_get_submodule_names(const struct ly_ctx *ctx, const char *module_name);
Radek Krejci96a10da2015-07-30 11:00:14 +0200210
211/**
Radek Krejcifd4e6e32015-08-10 15:00:51 +0200212 * @brief Get pointer to the schema tree of the module of the specified name.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200213 *
Radek Krejcida04f4a2015-05-21 12:54:09 +0200214 * @param[in] ctx Context to work in.
215 * @param[in] name Name of the YANG module to get.
Radek Krejcif647e612015-07-30 11:36:07 +0200216 * @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 Krejcifd4e6e32015-08-10 15:00:51 +0200219 * revision requirements is present in the context.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200220 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100221const struct lys_module *ly_ctx_get_module(const struct ly_ctx *ctx, const char *name, const char *revision);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200222
223/**
Michal Vasko82465962015-11-10 11:03:11 +0100224 * @brief Try to find the model in a specific directory and then the searchpath
225 * and load it into context.
226 *
227 * @param[in] ctx Context to add to.
228 * @param[in] dir Optional directory to search in first.
229 * @param[in] name Name of the module to load.
230 * @param[in] revision Optional revision date of the module. If not specified, it is
231 * assumed that there is only one model revision in the searchpath (the first matching file
232 * is parsed).
233 * @return Pointer to the data model structure, NULL if not found or some error occured.
234 */
235struct lys_module *ly_ctx_load_module(struct ly_ctx *ctx, const char *dir, const char *name, const char *revision);
236
237/**
Radek Krejcifd4e6e32015-08-10 15:00:51 +0200238 * @brief Get pointer to the schema tree of the module of the specified namespace
239 *
240 * @param[in] ctx Context to work in.
241 * @param[in] ns Namespace of the YANG module to get.
242 * @param[in] revision Optional revision date of the YANG module to get. If not specified,
243 * the schema in the newest revision is returned if any.
244 * @return Pointer to the data model structure, NULL if no schema following the namespace and
245 * revision requirements is present in the context.
246 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100247const struct lys_module *ly_ctx_get_module_by_ns(const struct ly_ctx *ctx, const char *ns, const char *revision);
Radek Krejcifd4e6e32015-08-10 15:00:51 +0200248
249/**
Michal Vasko7bf06882015-07-03 15:33:56 +0200250 * @brief Get submodule from the context's search dir.
251 *
252 * @param[in] module Parent (belongs-to) module.
253 * @param[in] name Name of the YANG submodule to get.
254 * @param[in] revision Optional revision date of the YANG submodule to get. If
255 * not specified, the newest revision is returned (TODO).
Michal Vasko7bf06882015-07-03 15:33:56 +0200256 * @return Pointer to the data model structure.
257 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100258const struct lys_submodule *ly_ctx_get_submodule(const struct lys_module *module, const char *name,
259 const char *revision);
Michal Vasko7bf06882015-07-03 15:33:56 +0200260
261/**
Radek Krejci704a7a92015-08-07 12:50:15 +0200262 * @brief Get schema node according to the given absolute schema node identifier.
263 *
Radek Krejci704a7a92015-08-07 12:50:15 +0200264 * @param[in] ctx Context to work in.
265 * @param[in] nodeid Absolute schema node identifier with module names used as
266 * prefixes. Prefix (module name) must be used whenever the child node is from
267 * other module (augments the parent node). The first node in the path must be
268 * always specified with the prefix. Here are some examples:
269 *
270 * - /ietf-netconf-monitoring:get-schema/input/identifier
271 * - /ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address/ip
272 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100273const struct lys_node *ly_ctx_get_node(const struct ly_ctx *ctx, const char *nodeid);
Radek Krejci704a7a92015-08-07 12:50:15 +0200274
275/**
Radek Krejci3045cf32015-05-28 10:58:52 +0200276 * @brief Free all internal structures of the specified context.
277 *
278 * The function should be used before terminating the application to destroy
279 * and free all structures internally used by libyang. If the caller uses
280 * multiple contexts, the function should be called for each used context.
281 *
282 * All instance data are supposed to be freed before destroying the context.
283 * Data models are destroyed automatically as part of ly_ctx_destroy() call.
284 *
285 * @param[in] ctx libyang context to destroy
Radek Krejcida04f4a2015-05-21 12:54:09 +0200286 */
Radek Krejci3045cf32015-05-28 10:58:52 +0200287void ly_ctx_destroy(struct ly_ctx *ctx);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200288
Radek Krejci26715a42015-07-29 14:10:45 +0200289/**@} context */
290
291/**
292 * @defgroup parsers Parsers
293 * @{
294 *
295 * Parsers allows to read schema and data trees from a specific format.
296 *
297 * For schemas, the following formats are supported:
298 * - YANG
299 *
300 * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020).
301 * Currently, only YANG 1.0 is supported.
302 *
303 * \todo YANG input is not yet implemented
304 *
305 * - YIN
306 *
307 * Alternative XML-based format to YANG. The details can be found in
308 * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11).
309 *
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200310 * For data instances, the following formats are supported:
311 * - \todo TBD
312 *
Radek Krejci26715a42015-07-29 14:10:45 +0200313 */
314
Radek Krejcida04f4a2015-05-21 12:54:09 +0200315/**
Radek Krejci704a7a92015-08-07 12:50:15 +0200316 * @brief Load a schema into the specified context.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200317 *
Radek Krejcib20c62d2015-07-07 17:07:14 +0200318 * LY_IN_YANG (YANG) format is not yet supported.
319 *
Radek Krejcida04f4a2015-05-21 12:54:09 +0200320 * @param[in] ctx libyang context where to process the data model.
321 * @param[in] data The string containing the dumped data model in the specified
Michal Vaskod8aa32d2015-07-24 11:50:01 +0200322 * format.
Radek Krejcida04f4a2015-05-21 12:54:09 +0200323 * @param[in] format Format of the input data (YANG or YIN).
324 * @return Pointer to the data model structure or NULL on error.
325 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100326const struct lys_module *lys_parse(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200327
Radek Krejci704a7a92015-08-07 12:50:15 +0200328/**
329 * @brief Read a schema from file into the specified context.
330 *
331 * LY_IN_YANG (YANG) format is not yet supported.
332 *
333 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
334 *
335 * @param[in] ctx libyang context where to process the data model.
Radek Krejci4910e242015-11-30 10:40:45 +0100336 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
337 * in the specified format.
Radek Krejci704a7a92015-08-07 12:50:15 +0200338 * @param[in] format Format of the input data (YANG or YIN).
339 * @return Pointer to the data model structure or NULL on error.
340 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100341const struct lys_module *lys_read(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200342
343/**
Radek Krejci25b9fd32015-08-10 15:06:07 +0200344 * @defgroup parseroptions Data parser options
345 * @ingroup parsers
346 *
347 * Various options to change the data tree parsers behavior.
348 *
349 * By default, parser silently ignores the data without a matching node in schema trees. If the caller want to stop
350 * parsing in case of presence of unknown data, the #LYD_OPT_STRICT can be used. The strict mode is useful for
351 * NETCONF servers, since NETCONF clients should always send data according to the capabilities announced by the server.
352 * On the other hand, the default non-strict mode is useful for clients receiving data from NETCONF server since
353 * clients are not required to understand everything the server does. Of course, the optimal strategy is to use
354 * filtering to get only the required data.
355 *
Radek Krejci20cdf632015-11-09 14:44:58 +0100356 * The #LYD_OPT_DESTRUCT option is used to optimize memory consumption profile of the parser in case the input
357 * data are no more needed after the parser function call. It continuously free the input data whenever it is
358 * processed for the output. This option is applicable only in case the input data are in the XML tree format.
359 *
Radek Krejci25b9fd32015-08-10 15:06:07 +0200360 * Parser also expects that the provided data are complete and performs data validation according to all
Radek Krejci20cdf632015-11-09 14:44:58 +0100361 * implemented YANG rules. This can be problem in case of representing NETCONF's subtree filter data,
362 * edit-config's data or the received data (after get or get-config request) where a filter was applied - such data
363 * do not represent a complete data set and different validation rules can fail. Therefore there are other options
364 * to make parser to accept such a data.
Radek Krejci25b9fd32015-08-10 15:06:07 +0200365 *
366 * @{
367 */
Radek Krejci20cdf632015-11-09 14:44:58 +0100368#define LYD_OPT_STRICT 0x01 /**< instead of silent ignoring data without schema definition, raise an error.
369 Having an unknown element of the known namespace is always an error. */
370#define LYD_OPT_DESTRUCT 0x02 /**< safe consumed memory and free the processed XML data continuously.
371 On success, only the top level XML element is kept in the end. This
372 option is applicable only with lyd_parse_xml(). */
373#define LYD_OPT_EDIT 0x04 /**< make validation to accept NETCONF edit-config's content:
374 - mandatory nodes can be omitted
375 - leafrefs and instance-identifier are not resolved
376 - status data are not allowed */
377#define LYD_OPT_FILTER 0x08 /**< make validation to accept NETCONF subtree filter data:
378 - leafs/leaf-lists with no data are allowed (even not allowed e.g. by length restriction)
379 - multiple instances of container/leaf/.. are allowed
380 - list's keys/unique nodes are not required
381 - mandatory nodes can be omitted
382 - leafrefs and instance-identifier are not resolved
383 - data from different choice's branches are allowed */
384#define LYD_OPT_GETCONFIG 0x10 /**< make validation to accept get-config's result data even with applied filter:
385 - mandatory nodes can be omitted
386 - leafrefs and instance-identifier are not resolved
387 - list's keys/unique nodes are not required (so duplication is not checked)
388 - status data are not allowed */
389#define LYD_OPT_GET 0x20 /**< make validation to accept get's result data even with applied filter:
390 - same as for #LYD_OPT_GETCONFIG but the status data are allowed */
Radek Krejci04b97de2015-10-31 23:09:15 +0100391
Radek Krejci25b9fd32015-08-10 15:06:07 +0200392/**
393 * @}
394 */
395
396/**
Radek Krejcib20c62d2015-07-07 17:07:14 +0200397 * @brief Parse (and validate according to appropriate schema from the given context) data.
398 *
Radek Krejci4f0a8742015-08-12 10:09:28 +0200399 * In case of LY_XML format, the data string is expected to contain XML data under a single
400 * XML element. The element is not parsed, but it is expected to keep XML data well formed in all
401 * cases. There are no restrictions for the element name or its namespace.
Radek Krejcib20c62d2015-07-07 17:07:14 +0200402 *
Radek Krejci26715a42015-07-29 14:10:45 +0200403 * @param[in] ctx Context to connect with the data tree being built here.
404 * @param[in] data Serialized data in the specified format.
405 * @param[in] format Format of the input data to be parsed.
Radek Krejci25b9fd32015-08-10 15:06:07 +0200406 * @param[in] options Parser options, see @ref parseroptions.
Radek Krejci26715a42015-07-29 14:10:45 +0200407 * @return Pointer to the built data tree. To free the returned structure, use lyd_free().
Radek Krejcib20c62d2015-07-07 17:07:14 +0200408 */
Radek Krejci25b9fd32015-08-10 15:06:07 +0200409struct lyd_node *lyd_parse(struct ly_ctx *ctx, const char *data, LYD_FORMAT format, int options);
Radek Krejcib20c62d2015-07-07 17:07:14 +0200410
Radek Krejci704a7a92015-08-07 12:50:15 +0200411/**
Radek Krejcic6704c82015-10-06 11:12:45 +0200412 * @brief Parse (and validate according to appropriate schema from the given context) XML tree.
413 *
414 * The output data tree is parsed from the given XML tree previously parsed by one of the
415 * lyxml_read* functions. Note, that the parser removes successfully parsed data from the
416 * XML tree except the root element (see the note about XML format in lyd_parse()). When
417 * the given XML tree is successfully parsed, the given \p root is kept but it has no children
418 * which are returned as a top level nodes in the output data tree.
419 *
420 * The context must be the same as the context used to parse XML tree by lyxml_read* function.
421 *
422 * @param[in] ctx Context to connect with the data tree being built here.
423 * @param[in] root XML tree to parse (convert) to data tree.
424 * @param[in] options Parser options, see @ref parseroptions.
425 * @return Pointer to the built data tree. To free the returned structure, use lyd_free().
426 */
427struct lyd_node *lyd_parse_xml(struct ly_ctx *ctx, struct lyxml_elem *root, int options);
428
429/**
Radek Krejci704a7a92015-08-07 12:50:15 +0200430 * @brief Read data from the given file
431 *
432 * TODO not implemented
433 *
434 * @param[in] ctx Context to connect with the data tree being built here.
435 * @param[in] fd The standard file descriptor of the file containing the data tree in the specified format.
436 * @param[in] format Format of the input data to be parsed.
Radek Krejci25b9fd32015-08-10 15:06:07 +0200437 * @param[in] options Parser options, see @ref parseroptions.
Radek Krejci704a7a92015-08-07 12:50:15 +0200438 * @return Pointer to the built data tree. To free the returned structure, use lyd_free().
439 */
Radek Krejci25b9fd32015-08-10 15:06:07 +0200440struct lyd_node *lyd_read(struct ly_ctx *ctx, int fd, LYD_FORMAT format, int options);
Radek Krejci704a7a92015-08-07 12:50:15 +0200441
Radek Krejci26715a42015-07-29 14:10:45 +0200442/**@} parsers */
443
Radek Krejcid9ba3e32015-07-30 15:08:18 +0200444/**
445 * @defgroup schematree Schema Tree
446 * @{
447 *
448 * Data structures and functions to manipulate and access schema tree.
449 *
450 * @}
451 */
452
453/**
454 * @defgroup datatree Data Tree
455 * @{
456 *
457 * Data structures and functions to manipulate and access instance data tree.
458 *
459 * @}
460 */
Radek Krejci9b4ca392015-04-10 08:31:27 +0200461
462/**
Radek Krejci26715a42015-07-29 14:10:45 +0200463 * @defgroup printers Printers
464 * @{
Radek Krejci9b4ca392015-04-10 08:31:27 +0200465 *
Radek Krejci26715a42015-07-29 14:10:45 +0200466 * Printers allows to serialize schema and data trees in a specific format.
Radek Krejci9b4ca392015-04-10 08:31:27 +0200467 *
Radek Krejci26715a42015-07-29 14:10:45 +0200468 * For schemas, the following formats are supported:
469 * - YANG
Radek Krejci9b4ca392015-04-10 08:31:27 +0200470 *
Radek Krejci26715a42015-07-29 14:10:45 +0200471 * Basic YANG schemas format described in [RFC 6020](http://tools.ietf.org/html/rfc6020).
472 * Currently, only YANG 1.0 is supported.
473 *
474 * - YIN
475 *
476 * Alternative XML-based format to YANG. The details can be found in
477 * [RFC 6020](http://tools.ietf.org/html/rfc6020#section-11).
478 *
479 * \todo YIN output is not yet implemented
480 *
481 * - Tree
482 *
483 * Simple tree structure of the module.
484 *
485 * - Info
486 *
487 * Detailed information about the specific node in the schema tree.
Michal Vasko6d6076e2015-08-13 15:53:09 +0200488 * The target can be more specific than the module itself:
Radek Krejci26715a42015-07-29 14:10:45 +0200489 *
Michal Vasko6d6076e2015-08-13 15:53:09 +0200490 * - absolute-schema-nodeid&nbsp;&nbsp;&nbsp;&nbsp;\a /modules/module-set-id in \a ietf-yang-library
491 * - <b>typedef/</b>typedef-name&nbsp;&nbsp;&nbsp;&nbsp;\a typedef/revision-identifier in \a ietf-yang-library
492 * - <b>feature/</b>feature-name&nbsp;&nbsp;&nbsp;&nbsp;\a feature/ssh in \a ietf-netconf-server
493 * - <b>grouping/</b>grouping-name/descendant-schema-nodeid&nbsp;&nbsp;&nbsp;&nbsp;\a grouping/module or \a grouping/module/module/submodules
494 * in \a ietf-yang-library
495 * - <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 +0200496 *
497 * For data instances, the following formats are supported:
498 * - \todo TBD
499 *
Radek Krejci9b4ca392015-04-10 08:31:27 +0200500 */
501
502/**
Radek Krejci912da452015-07-29 14:10:06 +0200503 * @brief Print schema tree in the specified format.
504 *
Radek Krejci87f52372015-10-09 09:34:46 +0200505 * To write data into a file descriptor, use lys_print_fd().
506 *
Radek Krejci912da452015-07-29 14:10:06 +0200507 * @param[in] module Schema tree to print.
508 * @param[in] f File stream where to print the schema.
509 * @param[in] format Schema output format.
Radek Krejcia9167ef2015-08-03 11:01:11 +0200510 * @param[in] target_node Optional parameter for ::LYS_OUT_INFO format. It specifies which particular
Radek Krejci912da452015-07-29 14:10:06 +0200511 * node in the module will be printed.
512 * @return 0 on success, 1 on failure (#ly_errno is set).
513 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100514int lys_print(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node);
Radek Krejci912da452015-07-29 14:10:06 +0200515
516/**
Radek Krejci87f52372015-10-09 09:34:46 +0200517 * @brief Print schema tree in the specified format.
518 *
519 * Same as lys_print(), but output is written into the specified file descriptor.
520 *
521 * @param[in] module Schema tree to print.
522 * @param[in] fd File descriptor where to print the data.
523 * @param[in] format Schema output format.
524 * @param[in] target_node Optional parameter for ::LYS_OUT_INFO format. It specifies which particular
525 * node in the module will be printed.
526 * @return 0 on success, 1 on failure (#ly_errno is set).
527 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100528int lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node);
Radek Krejci87f52372015-10-09 09:34:46 +0200529
530/**
Radek Krejci6140e4e2015-10-09 15:50:55 +0200531 * @brief Print schema tree in the specified format.
532 *
Radek Krejci2fa0fc12015-10-14 18:14:29 +0200533 * Same as lys_print(), but it allocates memory and store the data into it.
534 * It is up to caller to free the returned string by free().
535 *
536 * @param[out] strp Pointer to store the resulting dump.
537 * @param[in] module Schema tree to print.
538 * @param[in] format Schema output format.
539 * @param[in] target_node Optional parameter for ::LYS_OUT_INFO format. It specifies which particular
540 * node in the module will be printed.
541 * @return 0 on success, 1 on failure (#ly_errno is set).
542 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100543int lys_print_mem(char **strp, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node);
Radek Krejci2fa0fc12015-10-14 18:14:29 +0200544
545/**
546 * @brief Print schema tree in the specified format.
547 *
Radek Krejci6140e4e2015-10-09 15:50:55 +0200548 * Same as lys_print(), but output is written via provided callback.
549 *
550 * @param[in] module Schema tree to print.
551 * @param[in] writeclb Callback function to write the data (see write(1)).
Radek Krejci50929eb2015-10-09 18:14:15 +0200552 * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
Radek Krejci6140e4e2015-10-09 15:50:55 +0200553 * @param[in] format Schema output format.
554 * @param[in] target_node Optional parameter for ::LYS_OUT_INFO format. It specifies which particular
555 * node in the module will be printed.
556 * @return 0 on success, 1 on failure (#ly_errno is set).
557 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100558int lys_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
559 const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node);
Radek Krejci6140e4e2015-10-09 15:50:55 +0200560
561/**
Radek Krejci912da452015-07-29 14:10:06 +0200562 * @brief Print data tree in the specified format.
563 *
Radek Krejci87f52372015-10-09 09:34:46 +0200564 * To write data into a file descriptor, use lyd_print_fd().
565 *
Radek Krejci912da452015-07-29 14:10:06 +0200566 * @param[in] root Root node of the data tree to print. It can be actually any (not only real root)
567 * node of the data tree to print the specific subtree.
568 * @param[in] f File stream where to print the data.
569 * @param[in] format Data output format.
570 * @return 0 on success, 1 on failure (#ly_errno is set).
571 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100572int lyd_print(FILE *f, const struct lyd_node *root, LYD_FORMAT format);
Radek Krejci912da452015-07-29 14:10:06 +0200573
Radek Krejci87f52372015-10-09 09:34:46 +0200574/**
575 * @brief Print data tree in the specified format.
576 *
577 * Same as lyd_print(), but output is written into the specified file descriptor.
578 *
579 * @param[in] root Root node of the data tree to print. It can be actually any (not only real root)
580 * node of the data tree to print the specific subtree.
581 * @param[in] fd File descriptor where to print the data.
582 * @param[in] format Data output format.
583 * @return 0 on success, 1 on failure (#ly_errno is set).
584 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100585int lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format);
Radek Krejci87f52372015-10-09 09:34:46 +0200586
Radek Krejci2fa0fc12015-10-14 18:14:29 +0200587
588 /**
589 * @brief Print data tree in the specified format.
590 *
591 * Same as lyd_print(), but it allocates memory and store the data into it.
592 * It is up to caller to free the returned string by free().
593 *
594 * @param[out] strp Pointer to store the resulting dump.
595 * @param[in] root Root node of the data tree to print. It can be actually any (not only real root)
596 * node of the data tree to print the specific subtree.
597 * @param[in] format Data output format.
598 * @return 0 on success, 1 on failure (#ly_errno is set).
599 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100600int lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format);
Radek Krejci2fa0fc12015-10-14 18:14:29 +0200601
Radek Krejci6140e4e2015-10-09 15:50:55 +0200602/**
603 * @brief Print data tree in the specified format.
604 *
605 * Same as lyd_print(), but output is written via provided callback.
606 *
607 * @param[in] root Root node of the data tree to print. It can be actually any (not only real root)
608 * node of the data tree to print the specific subtree.
609 * @param[in] writeclb Callback function to write the data (see write(1)).
Radek Krejci50929eb2015-10-09 18:14:15 +0200610 * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
Radek Krejci6140e4e2015-10-09 15:50:55 +0200611 * @param[in] format Data output format.
612 * @return 0 on success, 1 on failure (#ly_errno is set).
613 */
Michal Vasko1e62a092015-12-01 12:27:20 +0100614int lyd_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
615 const struct lyd_node *root, LYD_FORMAT format);
Radek Krejci6140e4e2015-10-09 15:50:55 +0200616
Radek Krejci912da452015-07-29 14:10:06 +0200617/**@} printers */
618
619/**
Radek Krejci3045cf32015-05-28 10:58:52 +0200620 * @defgroup logger Logger
621 * @{
622 *
623 * Publicly visible functions and values of the libyang logger. For more
624 * information, see \ref howtologger.
625 */
626
627/**
628 * @typedef LY_LOG_LEVEL
629 * @brief Verbosity levels of the libyang logger.
630 */
631typedef enum {
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200632 LY_LLERR, /**< Print only error messages. */
633 LY_LLWRN, /**< Print error and warning messages. */
634 LY_LLVRB, /**< Besides errors and warnings, print some other verbose messages. */
635 LY_LLDBG /**< Print all messages including some development debug messages. */
Radek Krejci3045cf32015-05-28 10:58:52 +0200636} LY_LOG_LEVEL;
637
638/**
639 * @brief Set logger verbosity level.
640 * @param[in] level Verbosity level.
641 */
642void ly_verb(LY_LOG_LEVEL level);
643
644/**
645 * @typedef LY_ERR
Radek Krejci26715a42015-07-29 14:10:45 +0200646 * @brief libyang's error codes available via ly_errno extern variable.
Radek Krejci9b4ca392015-04-10 08:31:27 +0200647 * @ingroup logger
648 */
649typedef enum {
Radek Krejciae6817a2015-08-10 14:02:06 +0200650 LY_SUCCESS, /**< no error, not set by functions, included just to complete #LY_ERR enumeration */
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200651 LY_EMEM, /**< Memory allocation failure */
652 LY_ESYS, /**< System call failure */
653 LY_EINVAL, /**< Invalid value */
654 LY_EINT, /**< Internal error */
655 LY_EVALID /**< Validation failure */
Radek Krejci3045cf32015-05-28 10:58:52 +0200656} LY_ERR;
Radek Krejci26715a42015-07-29 14:10:45 +0200657/**
658 * @brief libyang specific errno.
659 */
Radek Krejci3045cf32015-05-28 10:58:52 +0200660extern LY_ERR ly_errno;
Radek Krejci9b4ca392015-04-10 08:31:27 +0200661
Radek Krejci3045cf32015-05-28 10:58:52 +0200662/**@} logger */
Radek Krejci9b4ca392015-04-10 08:31:27 +0200663
Radek Krejci39d8d0d2015-08-17 13:42:45 +0200664#ifdef __cplusplus
665}
666#endif
667
Radek Krejci9b4ca392015-04-10 08:31:27 +0200668#endif /* LY_LIBYANG_H_ */