Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 1 | /** |
| 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 |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
| 22 | struct ly_in; |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 23 | struct lys_module; |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * @addtogroup schematree |
| 27 | * @{ |
| 28 | */ |
| 29 | |
| 30 | /** |
| 31 | * @brief Schema input formats accepted by libyang [parser functions](@ref howtoschemasparsers). |
| 32 | */ |
| 33 | typedef 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 Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 45 | * @param[out] module Optional parsed module. |
| 46 | * @return LY_ERR value. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 47 | */ |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 48 | LY_ERR lys_parse(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, const struct lys_module **module); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 49 | |
| 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 Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 57 | * @param[in] data The string containing the dumped data model in the specified format. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 58 | * @param[in] format Format of the input data (YANG or YIN). |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 59 | * @param[out] module Optional parsed module. |
| 60 | * @return LY_ERR value. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 61 | */ |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 62 | LY_ERR lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format, const struct lys_module **module); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 63 | |
| 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 Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 76 | * @param[out] module Optional parsed module. |
| 77 | * @return LY_ERR value. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 78 | */ |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 79 | LY_ERR lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format, const struct lys_module **module); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 80 | |
| 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 Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 90 | * @param[out] module Optional parsed module. |
| 91 | * @return LY_ERR value. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 92 | */ |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 93 | LY_ERR lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format, const struct lys_module **module); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 94 | |
| 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 | */ |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 110 | LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision, |
| 111 | char **localfile, LYS_INFORMAT *format); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 112 | |
| 113 | /** @} schematree */ |
| 114 | |
| 115 | #ifdef __cplusplus |
| 116 | } |
| 117 | #endif |
| 118 | |
| 119 | #endif /* LY_PARSER_SCHEMA_H_ */ |