blob: 22b49bf3a6e6debf9c6b8c410cb95aa008932923 [file] [log] [blame]
Radek Krejcif0e1ba52020-05-22 15:14:35 +02001/**
2 * @file parser_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief Schema parsers for libyang
5 *
6 * Copyright (c) 2015-2020 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_PARSER_SCHEMA_H_
16#define LY_PARSER_SCHEMA_H_
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22struct ly_in;
Michal Vasko3a41dff2020-07-15 14:30:28 +020023struct lys_module;
Radek Krejcif0e1ba52020-05-22 15:14:35 +020024
25/**
26 * @addtogroup schematree
27 * @{
28 */
29
30/**
31 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
32 */
33typedef enum {
34 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
35 LYS_IN_YANG = 1, /**< YANG schema input format */
36 LYS_IN_YIN = 3 /**< YIN schema input format */
37} LYS_INFORMAT;
38
39/**
40 * @brief Load a schema into the specified context.
41 *
42 * @param[in] ctx libyang context where to process the data model.
43 * @param[in] in The input handle to provide the dumped data model in the specified format.
44 * @param[in] format Format of the schema to parse.
Michal Vasko3a41dff2020-07-15 14:30:28 +020045 * @param[out] module Optional parsed module.
46 * @return LY_ERR value.
Radek Krejcif0e1ba52020-05-22 15:14:35 +020047 */
Michal Vasko3a41dff2020-07-15 14:30:28 +020048LY_ERR lys_parse(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, const struct lys_module **module);
Radek Krejcif0e1ba52020-05-22 15:14:35 +020049
50/**
51 * @brief Load a schema into the specified context.
52 *
53 * This function is comsidered for a simple use, if you have a complex usecase,
54 * consider use of lys_parse() with a standalone input handler.
55 *
56 * @param[in] ctx libyang context where to process the data model.
Michal Vasko3a41dff2020-07-15 14:30:28 +020057 * @param[in] data The string containing the dumped data model in the specified format.
Radek Krejcif0e1ba52020-05-22 15:14:35 +020058 * @param[in] format Format of the input data (YANG or YIN).
Michal Vasko3a41dff2020-07-15 14:30:28 +020059 * @param[out] module Optional parsed module.
60 * @return LY_ERR value.
Radek Krejcif0e1ba52020-05-22 15:14:35 +020061 */
Michal Vasko3a41dff2020-07-15 14:30:28 +020062LY_ERR lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format, const struct lys_module **module);
Radek Krejcif0e1ba52020-05-22 15:14:35 +020063
64/**
65 * @brief Read a schema from file descriptor into the specified context.
66 *
67 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
68 *
69 * This function is comsidered for a simple use, if you have a complex usecase,
70 * consider use of lys_parse() with a standalone input handler.
71 *
72 * @param[in] ctx libyang context where to process the data model.
73 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
74 * in the specified format.
75 * @param[in] format Format of the input data (YANG or YIN).
Michal Vasko3a41dff2020-07-15 14:30:28 +020076 * @param[out] module Optional parsed module.
77 * @return LY_ERR value.
Radek Krejcif0e1ba52020-05-22 15:14:35 +020078 */
Michal Vasko3a41dff2020-07-15 14:30:28 +020079LY_ERR lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format, const struct lys_module **module);
Radek Krejcif0e1ba52020-05-22 15:14:35 +020080
81/**
82 * @brief Load a schema into the specified context from a file.
83 *
84 * This function is comsidered for a simple use, if you have a complex usecase,
85 * consider use of lys_parse() with a standalone input handler.
86 *
87 * @param[in] ctx libyang context where to process the data model.
88 * @param[in] path Path to the file with the model in the specified format.
89 * @param[in] format Format of the input data (YANG or YIN).
Michal Vasko3a41dff2020-07-15 14:30:28 +020090 * @param[out] module Optional parsed module.
91 * @return LY_ERR value.
Radek Krejcif0e1ba52020-05-22 15:14:35 +020092 */
Michal Vasko3a41dff2020-07-15 14:30:28 +020093LY_ERR lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format, const struct lys_module **module);
Radek Krejcif0e1ba52020-05-22 15:14:35 +020094
95/**
96 * @brief Search for the schema file in the specified searchpaths.
97 *
98 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
99 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
100 * result of the ly_ctx_get_searchdirs().
101 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
102 * @param[in] name Name of the schema to find.
103 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
104 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
105 * complying the provided restriction is found, NULL is set.
106 * @param[out] format Optional output variable containing expected format of the schema document according to the
107 * file suffix.
108 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
109 */
Radek Krejci857189e2020-09-01 13:26:36 +0200110LY_ERR lys_search_localfile(const char * const *searchpaths, ly_bool cwd, const char *name, const char *revision,
Radek Krejci0f969882020-08-21 16:56:47 +0200111 char **localfile, LYS_INFORMAT *format);
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200112
113/** @} schematree */
114
115#ifdef __cplusplus
116}
117#endif
118
119#endif /* LY_PARSER_SCHEMA_H_ */