blob: 82bdd9bad5a16d6f880f7f2c591ad33ee9587576 [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;
23
24/**
25 * @addtogroup schematree
26 * @{
27 */
28
29/**
30 * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers).
31 */
32typedef enum {
33 LYS_IN_UNKNOWN = 0, /**< unknown format, used as return value in case of error */
34 LYS_IN_YANG = 1, /**< YANG schema input format */
35 LYS_IN_YIN = 3 /**< YIN schema input format */
36} LYS_INFORMAT;
37
38/**
39 * @brief Load a schema into the specified context.
40 *
41 * @param[in] ctx libyang context where to process the data model.
42 * @param[in] in The input handle to provide the dumped data model in the specified format.
43 * @param[in] format Format of the schema to parse.
44 * @return Pointer to the data model structure or NULL on error.
45 */
46struct lys_module *lys_parse(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format);
47
48/**
49 * @brief Load a schema into the specified context.
50 *
51 * This function is comsidered for a simple use, if you have a complex usecase,
52 * consider use of lys_parse() with a standalone input handler.
53 *
54 * @param[in] ctx libyang context where to process the data model.
55 * @param[in] data The string containing the dumped data model in the specified
56 * format.
57 * @param[in] format Format of the input data (YANG or YIN).
58 * @return Pointer to the data model structure or NULL on error.
59 */
60struct lys_module *lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format);
61
62/**
63 * @brief Read a schema from file descriptor into the specified context.
64 *
65 * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc.
66 *
67 * This function is comsidered for a simple use, if you have a complex usecase,
68 * consider use of lys_parse() with a standalone input handler.
69 *
70 * @param[in] ctx libyang context where to process the data model.
71 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the schema
72 * in the specified format.
73 * @param[in] format Format of the input data (YANG or YIN).
74 * @return Pointer to the data model structure or NULL on error.
75 */
76struct lys_module *lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format);
77
78/**
79 * @brief Load a schema into the specified context from a file.
80 *
81 * This function is comsidered for a simple use, if you have a complex usecase,
82 * consider use of lys_parse() with a standalone input handler.
83 *
84 * @param[in] ctx libyang context where to process the data model.
85 * @param[in] path Path to the file with the model in the specified format.
86 * @param[in] format Format of the input data (YANG or YIN).
87 * @return Pointer to the data model structure or NULL on error.
88 */
89struct lys_module *lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format);
90
91/**
92 * @brief Search for the schema file in the specified searchpaths.
93 *
94 * @param[in] searchpaths NULL-terminated array of paths to be searched (recursively). Current working
95 * directory is searched automatically (but non-recursively if not in the provided list). Caller can use
96 * result of the ly_ctx_get_searchdirs().
97 * @param[in] cwd Flag to implicitly search also in the current working directory (non-recursively).
98 * @param[in] name Name of the schema to find.
99 * @param[in] revision Revision of the schema to find. If NULL, the newest found schema filepath is returned.
100 * @param[out] localfile Mandatory output variable containing absolute path of the found schema. If no schema
101 * complying the provided restriction is found, NULL is set.
102 * @param[out] format Optional output variable containing expected format of the schema document according to the
103 * file suffix.
104 * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
105 */
106LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format);
107
108/** @} schematree */
109
110#ifdef __cplusplus
111}
112#endif
113
114#endif /* LY_PARSER_SCHEMA_H_ */