Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file parser_internal.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief Internal structures and functions for libyang parsers |
| 5 | * |
| 6 | * Copyright (c) 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_INTERNAL_H_ |
| 16 | #define LY_PARSER_INTERNAL_H_ |
| 17 | |
| 18 | #include "parser.h" |
| 19 | #include "tree_schema_internal.h" |
| 20 | |
| 21 | /** |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 22 | * @brief Mask for checking LYD_PARSE_ options (@ref dataparseroptions) |
| 23 | */ |
| 24 | #define LYD_PARSE_OPTS_MASK 0xFFFF0000 |
| 25 | |
| 26 | /** |
| 27 | * @brief Mask for checking LYD_VALIDATEP_ options (@ref datavalidationoptions) |
| 28 | */ |
| 29 | #define LYD_VALIDATE_OPTS_MASK 0x0000FFFF |
| 30 | |
| 31 | /** |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 32 | * @brief Parser input structure specifying where the data are read. |
| 33 | */ |
| 34 | struct ly_in { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 35 | LY_IN_TYPE type; /**< type of the output to select the output method */ |
| 36 | const char *current; /**< Current position in the input data */ |
| 37 | const char *func_start; /**< Input data position when the last parser function was executed */ |
| 38 | const char *start; /**< Input data start */ |
| 39 | size_t length; /**< mmap() length (if used) */ |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 40 | union { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 41 | int fd; /**< file descriptor for LY_IN_FD type */ |
| 42 | FILE *f; /**< file structure for LY_IN_FILE and LY_IN_FILEPATH types */ |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 43 | struct { |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 44 | int fd; /**< file descriptor for LY_IN_FILEPATH */ |
| 45 | char *filepath; /**< stored original filepath */ |
| 46 | } fpath; /**< filepath structure for LY_IN_FILEPATH */ |
| 47 | } method; /**< type-specific information about the output */ |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | /** |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 51 | * @brief Read bytes from an input. |
| 52 | * |
| 53 | * @param[in] in Input structure. |
| 54 | * @param[in] buf Destination buffer. |
| 55 | * @param[in] count Number of bytes to read. |
| 56 | * @return LY_SUCCESS on success, |
| 57 | * @return LY_EDENIED on EOF. |
| 58 | */ |
| 59 | LY_ERR ly_in_read(struct ly_in *in, void *buf, size_t count); |
| 60 | |
| 61 | /** |
| 62 | * @brief Just skip bytes in an input. |
| 63 | * |
| 64 | * @param[in] in Input structure. |
| 65 | * @param[in] count Number of bytes to skip. |
| 66 | * @return LY_SUCCESS on success, |
| 67 | * @return LY_EDENIED on EOF. |
| 68 | */ |
| 69 | LY_ERR ly_in_skip(struct ly_in *in, size_t count); |
| 70 | |
| 71 | /** |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 72 | * @brief Parse submodule from YANG data. |
| 73 | * @param[in,out] ctx Parser context. |
| 74 | * @param[in] ly_ctx Context of YANG schemas. |
| 75 | * @param[in] main_ctx Parser context of main module. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 76 | * @param[in] in Input structure. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 77 | * @param[out] submod Pointer to the parsed submodule structure. |
| 78 | * @return LY_ERR value - LY_SUCCESS, LY_EINVAL or LY_EVALID. |
| 79 | */ |
| 80 | LY_ERR yang_parse_submodule(struct lys_yang_parser_ctx **context, struct ly_ctx *ly_ctx, struct lys_parser_ctx *main_ctx, |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 81 | struct ly_in *in, struct lysp_submodule **submod); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * @brief Parse module from YANG data. |
| 85 | * @param[in] ctx Parser context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 86 | * @param[in] in Input structure. |
| 87 | * @param[in,out] mod Prepared module structure where the parsed information, including the parsed |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 88 | * module structure, will be filled in. |
| 89 | * @return LY_ERR value - LY_SUCCESS, LY_EINVAL or LY_EVALID. |
| 90 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 91 | LY_ERR yang_parse_module(struct lys_yang_parser_ctx **context, struct ly_in *in, struct lys_module *mod); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * @brief Parse module from YIN data. |
| 95 | * |
| 96 | * @param[in,out] yin_ctx Context created during parsing, is used to finalize lysp_model after it's completly parsed. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 97 | * @param[in] in Input structure. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 98 | * @param[in,out] mod Prepared module structure where the parsed information, including the parsed |
| 99 | * module structure, will be filled in. |
| 100 | * |
| 101 | * @return LY_ERR values. |
| 102 | */ |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 103 | LY_ERR yin_parse_module(struct lys_yin_parser_ctx **yin_ctx, struct ly_in *in, struct lys_module *mod); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * @brief Parse submodule from YIN data. |
| 107 | * |
| 108 | * @param[in,out] yin_ctx Context created during parsing, is used to finalize lysp_model after it's completly parsed. |
| 109 | * @param[in] ctx Libyang context. |
| 110 | * @param[in] main_ctx Parser context of main module. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 111 | * @param[in] in Input structure. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 112 | * @param[in,out] submod Submodule structure where the parsed information, will be filled in. |
| 113 | * @return LY_ERR values. |
| 114 | */ |
| 115 | LY_ERR yin_parse_submodule(struct lys_yin_parser_ctx **yin_ctx, struct ly_ctx *ctx, struct lys_parser_ctx *main_ctx, |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 116 | struct ly_in *in, struct lysp_submodule **submod); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 117 | |
| 118 | #endif /* LY_PARSER_INTERNAL_H_ */ |