blob: 9dc3c507645f1693b41bc117bbf3b2eeeb1b8338 [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/**
22 * @brief Parser input structure specifying where the data are read.
23 */
24struct ly_in {
25 LY_IN_TYPE type; /**< type of the output to select the output method */
26 const char *current;
27 const char *start;
28 size_t length;
29 union {
30 int fd; /**< file descriptor for LY_IN_FD type */
31 FILE *f; /**< file structure for LY_IN_FILE and LY_IN_FILEPATH types */
32 struct {
33 int fd; /**< file descriptor for LY_IN_FILEPATH */
34 char *filepath; /**< stored original filepath */
35 } fpath; /**< filepath structure for LY_IN_FILEPATH */
36 } method; /**< type-specific information about the output */
37};
38
39/**
40 * @brief Parse submodule from YANG data.
41 * @param[in,out] ctx Parser context.
42 * @param[in] ly_ctx Context of YANG schemas.
43 * @param[in] main_ctx Parser context of main module.
44 * @param[in] data Input data to be parsed.
45 * @param[out] submod Pointer to the parsed submodule structure.
46 * @return LY_ERR value - LY_SUCCESS, LY_EINVAL or LY_EVALID.
47 */
48LY_ERR yang_parse_submodule(struct lys_yang_parser_ctx **context, struct ly_ctx *ly_ctx, struct lys_parser_ctx *main_ctx,
49 const char *data, struct lysp_submodule **submod);
50
51/**
52 * @brief Parse module from YANG data.
53 * @param[in] ctx Parser context.
54 * @param[in] data Input data to be parsed.
55 * @param[in, out] mod Prepared module structure where the parsed information, including the parsed
56 * module structure, will be filled in.
57 * @return LY_ERR value - LY_SUCCESS, LY_EINVAL or LY_EVALID.
58 */
59LY_ERR yang_parse_module(struct lys_yang_parser_ctx **context, const char *data, struct lys_module *mod);
60
61/**
62 * @brief Parse module from YIN data.
63 *
64 * @param[in,out] yin_ctx Context created during parsing, is used to finalize lysp_model after it's completly parsed.
65 * @param[in] data Input data to be parsed.
66 * @param[in,out] mod Prepared module structure where the parsed information, including the parsed
67 * module structure, will be filled in.
68 *
69 * @return LY_ERR values.
70 */
71LY_ERR yin_parse_module(struct lys_yin_parser_ctx **yin_ctx, const char *data, struct lys_module *mod);
72
73/**
74 * @brief Parse submodule from YIN data.
75 *
76 * @param[in,out] yin_ctx Context created during parsing, is used to finalize lysp_model after it's completly parsed.
77 * @param[in] ctx Libyang context.
78 * @param[in] main_ctx Parser context of main module.
79 * @param[in,out] data Input data to be parsed.
80 * @param[in,out] submod Submodule structure where the parsed information, will be filled in.
81 * @return LY_ERR values.
82 */
83LY_ERR yin_parse_submodule(struct lys_yin_parser_ctx **yin_ctx, struct ly_ctx *ctx, struct lys_parser_ctx *main_ctx,
84 const char *data, struct lysp_submodule **submod);
85
86#endif /* LY_PARSER_INTERNAL_H_ */