blob: f60e5bdc2d2131dec574f9427ff80dbd14e48311 [file] [log] [blame]
Radek Krejcif0e1ba52020-05-22 15:14:35 +02001/**
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 Krejci7931b192020-06-25 17:05:03 +020022 * @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 Krejcif0e1ba52020-05-22 15:14:35 +020032 * @brief Parser input structure specifying where the data are read.
33 */
34struct ly_in {
Michal Vasko63f3d842020-07-08 10:10:14 +020035 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 Krejcif0e1ba52020-05-22 15:14:35 +020040 union {
Michal Vasko63f3d842020-07-08 10:10:14 +020041 int fd; /**< file descriptor for LY_IN_FD type */
42 FILE *f; /**< file structure for LY_IN_FILE and LY_IN_FILEPATH types */
Radek Krejcif0e1ba52020-05-22 15:14:35 +020043 struct {
Michal Vasko63f3d842020-07-08 10:10:14 +020044 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 Krejcif0e1ba52020-05-22 15:14:35 +020048};
49
50/**
Michal Vasko63f3d842020-07-08 10:10:14 +020051 * @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 */
59LY_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 */
69LY_ERR ly_in_skip(struct ly_in *in, size_t count);
70
71/**
Radek Krejcif0e1ba52020-05-22 15:14:35 +020072 * @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 Vasko63f3d842020-07-08 10:10:14 +020076 * @param[in] in Input structure.
Radek Krejcif0e1ba52020-05-22 15:14:35 +020077 * @param[out] submod Pointer to the parsed submodule structure.
78 * @return LY_ERR value - LY_SUCCESS, LY_EINVAL or LY_EVALID.
79 */
80LY_ERR yang_parse_submodule(struct lys_yang_parser_ctx **context, struct ly_ctx *ly_ctx, struct lys_parser_ctx *main_ctx,
Michal Vasko63f3d842020-07-08 10:10:14 +020081 struct ly_in *in, struct lysp_submodule **submod);
Radek Krejcif0e1ba52020-05-22 15:14:35 +020082
83/**
84 * @brief Parse module from YANG data.
85 * @param[in] ctx Parser context.
Michal Vasko63f3d842020-07-08 10:10:14 +020086 * @param[in] in Input structure.
87 * @param[in,out] mod Prepared module structure where the parsed information, including the parsed
Radek Krejcif0e1ba52020-05-22 15:14:35 +020088 * module structure, will be filled in.
89 * @return LY_ERR value - LY_SUCCESS, LY_EINVAL or LY_EVALID.
90 */
Michal Vasko63f3d842020-07-08 10:10:14 +020091LY_ERR yang_parse_module(struct lys_yang_parser_ctx **context, struct ly_in *in, struct lys_module *mod);
Radek Krejcif0e1ba52020-05-22 15:14:35 +020092
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 Vasko63f3d842020-07-08 10:10:14 +020097 * @param[in] in Input structure.
Radek Krejcif0e1ba52020-05-22 15:14:35 +020098 * @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 Vasko63f3d842020-07-08 10:10:14 +0200103LY_ERR yin_parse_module(struct lys_yin_parser_ctx **yin_ctx, struct ly_in *in, struct lys_module *mod);
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200104
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 Vasko63f3d842020-07-08 10:10:14 +0200111 * @param[in] in Input structure.
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200112 * @param[in,out] submod Submodule structure where the parsed information, will be filled in.
113 * @return LY_ERR values.
114 */
115LY_ERR yin_parse_submodule(struct lys_yin_parser_ctx **yin_ctx, struct ly_ctx *ctx, struct lys_parser_ctx *main_ctx,
Michal Vasko63f3d842020-07-08 10:10:14 +0200116 struct ly_in *in, struct lysp_submodule **submod);
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200117
118#endif /* LY_PARSER_INTERNAL_H_ */